Click to See Complete Forum and Search --> : Problem with radio buttons


hungrydino
08-31-2003, 07:31 PM
I'm having trouble using radiobuttons in a javascript program I'm putting together.

<form name="form1" method="post" action="">>
<input type="radio" name="radiobutton" value="ten">
<input type="radio" name="radiobutton" value="eleven">
</form>


I try to find out what radiobutton is selected from a function between the <head> tags.

I'm trying to find the value like this:

variable = self.form1.radiobutton.value

OR

if (self.form1.radiobutton.ten.checked == true)

and other variations but I haven't been able to find which radiobutton has been selected. Please help. Thanks.

Stephen

hungrydino
08-31-2003, 07:33 PM
ignore the second ">", it was a typo in the post, not the script. Thanks.

Stephen

Xin
09-01-2003, 12:12 AM
you might want to use:

if (document.form1.radiobutton[0].checked) { ... }

or form a loop to test the document.form1.radiobutton array.

lillu
09-01-2003, 02:37 AM
Hi all,

Just for clarity here's a very simple function that loops through the radioGroup (the name I gave the radio buttons). form1 is the name of the form in which the radio buttons live.

function checkRadio()
{

for (i=0; i<document.form1.radioGroup.length; i++)
{
if (document.form1.radioGroup[i].checked == true)
{ // code to do something with the checked button }
}
}