Web Hosting Talk







View Full Version : Getting the value of a radio group? Javascript


VolkNet
05-10-2005, 05:52 PM
I am having trouble obtaining the value of what radio button has been selected.

i have this in the head
...
function setCook(){
if(document.forms['Signup'].package_type.value == 'gold'){
alert('gold!!');
}
else if(document.forms['Signup'].package_type.value =='silver'){
alert('SILVER!');
}
else alert('fail');
}
...



Then i have a form as so.

<form name="Signup" id="Signup" method="post" action="https://www.paypal.com/cgi-bin/webscr" onSubmit="setCook();">
<input name="package_type" id="package_type" type="radio" onClick="updateForm_link();" value="silver" checked>
<input type="radio" name="package_type" id="package_type" value="gold" onClick="updateForm_art();">
...
</form>


This always returns with "fail" :( Can someone shed some light? Thanks :)

BurstChris
05-12-2005, 12:40 AM
Radio buttons are arrays

document.forms['Signup'].package_type[0].value

should probably do what you are looking for, normally you may want to loop thru the radio buttons to find out which one is checked, and then get the value of that.