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 Back to top |
|||||
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. Back to top |
|||||
All times are GMT - 8 Hours
|