Page 1 of 1

How to replace field value with a random number

Posted: Fri Jan 24, 2014 12:53 am
by Ralcala
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.

Re: How to replace field value with a random number

Posted: Fri Jan 24, 2014 11:09 am
by massiws
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

Re: How to replace field value with a random number

Posted: Fri Jan 24, 2014 7:57 pm
by Ralcala
Thank you max. Kind as always thank you for your support.

Re: How to replace field value with a random number

Posted: Sat Jan 25, 2014 11:17 am
by massiws
.