How to replace field value with a random number

How to replace field value with a random number

Postby Ralcala » Fri Jan 24, 2014 9:23 am

Hi NB Team happy new year.

I just need to generate a random 9 digit number after ADD RECORD button are pressed and update field value with it. Sorry to say i have tried JS on Custom Code After Open tab but no results please give an advice or clue

Thanks guys.
Ralcala
 
Posts: 11
Joined: Fri Aug 16, 2013 11:44 pm

Re: How to replace field value with a random number

Postby massiws » Fri Jan 24, 2014 7:39 pm

Ralcala wrote:... i have tried JS on Custom Code After Open tab ...

After Open tab??
Javascript code must be inserted in Javascript tab: all other tabs in Custom Code are for PHP code.

To make your job you could:
  • insert js like this in Form > Custom Code > Javascript > nuLoadThis() function:
    Code: Select all
    function nuLoadThis() {

      $('#my_field').val(Math.floor(Math.random() * 999999999) + 1);

    }
  • insert SQL code like this in Object > Default Value SQL field:
    Code: Select all
    SELECT FLOOR(1 + (RAND() * 999999999));

Hope this helps,
Max
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy

Re: How to replace field value with a random number

Postby Ralcala » Sat Jan 25, 2014 4:27 am

Thank you max. Kind as always thank you for your support.
Ralcala
 
Posts: 11
Joined: Fri Aug 16, 2013 11:44 pm

Re: How to replace field value with a random number

Postby massiws » Sat Jan 25, 2014 7:47 pm

.
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy


Return to Custom Code