Copy codeThe Code is as follows:
<! 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 = "text/html; charset = gb2312"/>
<Title> example of js obtaining the radio button value </title>
</Head>
<Body>
<Form id = "form1" name = "form1" method = "post" action = "">
<P>
<Label>
<Input type = "radio" name = "RadioGroup1" value = "single choice" id = "RadioGroup1_0"/>
Single choice </label>
<Br/>
<Label>
<Input type = "radio" name = "RadioGroup1" value = "single choice" id = "RadioGroup1_1"/>
Single choice </label>
<Br/>
<Label>
<Input name = "RadioGroup1" type = "radio" id = "RadioGroup1_2" value = "single choice"/>
Single choice </label>
<Br/>
<Label>
<Input type = "radio" name = "RadioGroup1" value = "single choice" id = "RadioGroup1_3"/>
Single choice </label>
<Input type = "submit" name = "button" id = "button" value = "submit" onclick = "javascript: return checksubmit ()"/>
<Br/>
</P>
</Form>
<Script>
Function checksubmit ()
{
If (GetRadioValue ('radiogroup1 '))
{
Alert ('select ');
}
Else
{
Alert ('unselect ');
}
}
Function GetRadioValue (RadioName ){
Var obj;
Obj = document. getElementsByName (RadioName );
If (obj! = Null ){
Var I;
For (I = 0; I <obj. length; I ++ ){
If (obj [I]. checked ){
Return obj [I]. value;
}
}
}
Return null;
}
</Script>
</Body>
</Html>