Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio button value 1

Status
Not open for further replies.

DaveC426913

Programmer
Jul 28, 2003
274
CA
Huh. A search returns zero hits for 'radio'.

Anyway, hopw can I return the value of a radio button selection?

I thought one of these might:

form.radiobutton.value
form.radiobutton.checked.value
form.radiobutton.selectedIndex.value
 
depends. If you have two radio buttons (or more) with the same name, then something like this:

Code:
var theVal = document.forms['formname'].elements['radioname'][red][0][/red].value;

Where 0 is the first radio button, 1 is the second, etc.

*cLFlaVA
----------------------------
[tt]clean slate...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
That doesn't tell me which is checked though does it? Do I have to loop through them?
 
yup. general concept:

Code:
var val;
var rbGroup = document.forms['formname'].elements['radioname'];
for (var i = 0; i < rbGroup.length; i++) {
    if (rbGroup[i].checked) {
        val = rbGroup[i].value;
        break;
    }
    alert(val);
}

*cLFlaVA
----------------------------
[tt]clean slate...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top