Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random variable

Status
Not open for further replies.

kpdvx

Programmer
Dec 1, 2001
87
US
I have four variables.
$answer1, $answer2, $answer3 and $rightanswer.

I have a set of radio buttons.
<INPUT TYPE=RADIO NAME=&quot;guess&quot; VALUE=&quot;1&quot;>answer<BR>
<INPUT TYPE=RADIO NAME=&quot;guess&quot; VALUE=&quot;2&quot;>answer<BR>
<INPUT TYPE=RADIO NAME=&quot;guess&quot; VALUE=&quot;3&quot;>answer<BR>
<INPUT TYPE=RADIO NAME=&quot;guess&quot; VALUE=&quot;4&quot;>answer<BR>

I want to put those variable names in randomly so that each time the correct answer is different. Is there any way to do this.. and allow for me to know which radio button was clicked?
 
your question is not very clear - but you can use the code below for writing a random text string to the html code using php.

--------------

$anames = array('answer1', 'answer2', 'answer3', 'answer4');

srand ( (double) microtime() * 1000000);
// when generating a random number, be sure to use srand() only once in the script, not more. (do not include srand inside a loop of any kind)

$r = rand(0,3);
// rand() syntax: rand(lowestnumber,highestnumber);

$name = $anames[$r];

print('<INPUT TYPE=RADIO NAME=&quot;guess&quot; VALUE=&quot;1&quot;>' . $name . '<BR>');


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top