In fact, the value of JS to get Radio is very simple, if it is a radio button group to traverse the line, if the radio is directly judged. Value on the line.
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd" >
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/>
<TITLE>JS Get Radio Value </title>
<script>
function Radiogroup ()
{
for (var i=0;i<formobj.a.length;i++) {
if (formobj.a[i].checked) {
Alert ("Select box selected:" + formobj.a[i].value);
return true;
}
}
alert ("Unchecked");
return false;
}
</script>
Instance two
<script>
function Search (obj)
{
var Urlparam
For (I=0;i<obj.getelementsbytagname ("input"). length-1;i++)
{
if (Obj.getelementsbytagname ("input") [i].checked)
{
Urlparam=obj.getelementsbytagname ("input") [I].value
Break
}
}
obj.action+= "&sjprice=" +urlparam
return True
}
</script>
</head>
<body>
<form id= "form" name= "form" method= "POST" action= ""
<p>
<LABEL>
<input type= "Radio" name= "radiogroup1[" "value=" 1 "id=" Radiogroup1_0 "/>
Radio </label>
<br/>
<label>
<input type= "Radio" name= "radiogroup1[" Value= "1" id= "Radiogroup1_1"/>
Radio </label>
<br />
<label>
<input type= Radio "Name=" Radiogroup1[] "value=" 1 "id=" radiogroup1_2 "/>
Radio </label>
<br/>
<label>
<input type= " Radio "Name=" radiogroup1[] "value=" 1 "id=" radiogroup1_3 "/>
&nbsP; Radio </label>
</P>
<p>
<input type= button "Name=" Button "id=" button "value=" detect " onclick=" Web effects: Radiogroup ();/>
<br/>
</p>
</form>
</body>
</html>
Method Three
A section of JS get radio a set of selected values of the code, issued to share with you!
Preview function
var colorid= "";
function Showtemp ()
{
var eless = document.getelementsbyname ("Colorstyle");
for (Var i=0;i<eless.length;i++)
{
alert (eless[i].checked+eless[i].name+eless[i].id);
if (eless[i].checked)
{
Colorid=eless[i].value;
Break;
}
}
Alert (colorid+ "-");
}
Method Four, a complete example
<script lanage= "JavaScript" >
function Isid ()
{
alert (Document.all.gender.value);
if (document.all.gender.value= ' new ')
{
Eval ("document.all.emp.style.display= ' block ')"
return false;
}else
{
Eval ("document.all.emp.style.display= ' None")
return true;
}
}
Function foo ()
{
var selectedindex =-1;
var Form1 = document.getElementById ("Form1");
var i = 0;
for (i=0 i<form1.gender.length; i++)
{
if (form1.gender[i].checked)
{
selectedindex = i;
alert ("The value of your selected item is:" + form1.gender[i].value);
break;
}
}
if (SelectedIndex < 0)
{
alert ("You have not selected any items");
}
}
</script>
<bodY>
<form method= "POST"
<table>
<tr><td>
<input type = "Radio" value= "new"/>
employee
<input type= "Radio" value= "old" checked = "Checked"/>
old employee
<input type= "text"/>
</td>
< /tr>
</table>
</form>
</body>
</html>