This topic is locked

button

6/25/2010 3:02:11 AM
PHPRunner General questions
M
munkeh author

Hello,
I want to create a button that updates a record with a random number between 1109867 and 9548659.

In the record there is already filled in a number (which we can replace with the new random number, we do not need the old number anymore)

Can someone help me with the syntax? (the button creation is no problem with the editor)

A
ann 6/25/2010

Hi,
use PHP function rand() to generate random number.

Here is a sample:

$values["FieldName"]=rand(1109867, 9548659);

where FieldName is actual field name.

More information:

http://php.net/manual/en/function.rand.php
Use code of the Check if specific record exists predefined action just after to prevent doubling:

http://xlinesoft.com/phprunner/docs/check_if_specific_record_exists.htm

M
munkeh author 6/28/2010

Hi,
How do we put this code behind a button?

In the editor we use the 'insert button' option but how and what code do we use on the button to put this random number in the field named "code"?
Thanks in advance,

Regards,

J
Jane 6/28/2010

Hi,
to fill field with random value on the fly using custom button add custom JavaScript code to the 'Clint before' or 'Client after' section of your button.

Check JavaScript random() method:

http://www.w3schools.com/jsref/jsref_random.asp

M
munkeh author 6/28/2010



Hi,
to fill field with random value on the fly using custom button add custom JavaScript code to the 'Clint before' or 'Client after' section of your button.

Check JavaScript random() method:

http://www.w3schools.com/jsref/jsref_random.asp


Hi Jane,
the javascript generator works (a new html window pops up with the generated number in it)

Is there now an easy way to get this in the correct field in our database?
I will stop hassling you after that <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=50833&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

A
ann 6/29/2010

Hi,
use Insert button option on the Visual Editor tab, then add this code to the Client Before section:

document.forms.editform1.value_FieldName_1.value=Math.floor(Math.random()*(9548659-1109867)+1109867)"



where FieldName is your actual field name.