Forum Moderators: open

Message Too Old, No Replies

Radio Buttons

Two sets of radio buttons

         

TheSooner3

8:51 pm on Dec 5, 2009 (gmt 0)

10+ Year Member



Hi everybody. So I am in a basic computer science class; therefore, I am not too tech-savvy with Javascript. So I have one form containing two different sets of radio buttons:

First set: Medium Pizza - $8.00
<input id="r1" value="1" name="RadioGroup" type="radio" checked>
</br>
Large Pizza - $10.00
<input id="r2" value="2" name="RadioGroup" type="radio">
</br></br>

Second set: Pick-Up
<input id="r1" value="1" name="RadioGroup" type="radio" checked>
</br>
Delivery - $3.00
<input id="r2" value="2" name="RadioGroup" type="radio">
</br></br>

Sorry for the pizza examples, that is just what my project is. Anyway, I need to get these in two different sets, currently only ONE of these four can be active at a time. Any help would be much appreciated.

TheSooner3

10:15 pm on Dec 5, 2009 (gmt 0)

10+ Year Member



Nevermind. After plenty of different attempts, I figured it out and I feel quite stupid. I just changed the names of the each radio group

IE name="RadioGroup1"
name="RadioGroup1"
name="RadioGroup2"
name="RadioGroup2"

and it seems to work just fine.

rocknbil

6:49 pm on Dec 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard TheSooner3, sometimes you just have to see it typed out in front of you to see the solution. :-) For what's likely the next step in your project, note that each group is an array:

formname.RadioGroup[0].value = 1
formname.RadioGroup[1].value = 2
formname.RadioGroup2[0].value = 1
formname.RadioGroup2[1].value = 2

Or use document.getElementById:

document.getElementById('r1').value=1
document.getElementById('r2').value=2

Note that you can only have a single id'ed element per page - in your first example you have both r1 and r2 ID'ed twice. Change the second group id's to r3 and r4.

TheSooner3

12:40 am on Dec 7, 2009 (gmt 0)

10+ Year Member



Awesome! Thanks for being so helpful.