ss123
Status: Curious
Joined: 31 Mar 2005
Posts: 7
Back to top
Posted: Jun 30, 05, 5:32    retreive the value of the radio button
How do I retrieve the values of the selected radio button.

My html is as follows:

<input type=radio name=sel value=’testA’ id=13A onclick=test();>

<input type=radio name=sel value=’testB’ id=13B onclick=test();>


This statement always retrieves the first radio button which is testA
alert(document.getElementById(‘sel’).value);



The ids are different, so what is the syntax to retrieve the values by id.

Thanks
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 583
Back to top
Posted: Jun 30, 05, 8:23    
If you are using javascript, you have to use a slightly different method for extracting data from radio button lists:

:: Code ::
for (i = 0;  i < theForm.sel.length;  i++)
{
   if (theForm.sel[i].checked)
   alert( theForm.sel[i].value );
}

theForm would be the name of the form.

You're getting the first item in the radio button array because you're not looping through it is my guess.
Display posts from previous:   

All times are GMT - 8 Hours