radio buttons in html

2 replies [Last post]
roopalisaxena2
Offline
Last seen: 10 years 20 weeks ago
Joined: 2009-11-15
bOt Points: 58

can we have multiple values for a single radio button?

or what if you want to pass 2 values through radio button to another page on submitting the form.............. how do we do that?

shashwat
Offline
Last seen: 1 year 31 weeks ago
Joined: 2009-02-18
bOt Points: 1160
Hello roopalisaxena2, Yes you

Hello roopalisaxena2,

Yes you can pass multiple values for a single radio button. Check out the following example -

<input type="radio" name="choice" value="apple banana orange"/>

The different values have been separated by a space. You can also use a different separator.

While submitting this form use the following PHP code (on the next page) to extract all the values -

list($fruit1, $fruit2, $fruit3) = explode(" ", $POST["choice"]);

So your variables $fruit1, $fruit2 and $fruit3 will now contain the different values of the radio button.

If you use a different separator just change the explode function accordingly for example -

<input type="radio" name="choice" value="apple|banana|orange"/> 

list($fruit1, $fruit2, $fruit3) = explode("|", $POST["choice"]);

Founder and Admin

roopalisaxena2
Offline
Last seen: 10 years 20 weeks ago
Joined: 2009-11-15
bOt Points: 58
thank u so

thank u so much................ this has solved a major problem which me n my friend have been brainstorming about

thanks a ton...........