Forum Moderators: coopster

Message Too Old, No Replies

Radio buttons

         

FayeN

5:35 am on Nov 8, 2003 (gmt 0)

10+ Year Member



I have an electronic voting system where for example when you vote for president there are 3 radio buttons representing each of the three candidates. I would like to assign which ever radio button they choose to a president variable.

If candidate one is selected then
assign candidate one to = president variable.

But I am not sure of the syntax?

hakre

7:47 am on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi fayne, i don't know if i get you right, but with options in html-forms, it goes like this (demo-code):


<form action="out.php" method="post">
<input type="option" id="choice1" name="choice" value="mc carthy" /><label for="choice1">mc carthy</label> <br />
<input type="option" id="choice2" name="choice" value="nixon" /><label for="choice2">nixon</label> <br />
<input type="option" id="choice3" name="choice" value="bush" /><label for="choice3">bush</label> <br />
<br />
<input type="submit" />
</form>

after pressing submit, the variable

$choice
should contain the value selected. is it that, what you were looking for?

FayeN

5:07 pm on Nov 8, 2003 (gmt 0)

10+ Year Member



Well actually there are three radio buttons

cb1
cb2
cb3 my president variable is $President

so I am trying to say

If cb1 is clicked then
assign cb1 = $President

else
if cb2 is clicked then
assign cb2 = $President

else
if cb3 is clicked then
assign cb3 = $President

then upon hitting the submit button which ever candidate they voted for would be stored in the variable $President so that I can call that variable on the results page. The code that you gave before is that what it does?

thanks,
Faye

hakre

10:40 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yes it does. just change the
name="choice"
to
name="president"
and you don't even need to assign anything further ;)

-hakre