Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

How to replace field value with a random number

Locked
Ralcala
Posts: 11
Joined: Fri Aug 16, 2013 4:14 pm

How to replace field value with a random number

Unread post 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.
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: How to replace field value with a random number

Unread post 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
Ralcala
Posts: 11
Joined: Fri Aug 16, 2013 4:14 pm

Re: How to replace field value with a random number

Unread post by Ralcala »

Thank you max. Kind as always thank you for your support.
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: How to replace field value with a random number

Unread post by massiws »

.
Locked