About determining whether a radio box is checked for detailed instructions
It's a core piece of code.
for (Var i=0,l=radios.length;i<l;i++)
{
if (!hash[radios[i].name])
Hash[radios[i].name] = [Radios[i]]
Else
Hash[radios[i].name].push (Radios[i]);
}
Now let's take a look at the detailed application examples
<body>
<input type= "Radio" Name= "a" checked=checked value= "addd"/><input type= "Radio" Name= "a" value= "ACCC"/> <input type= "Radio" Name= "a" value= "ACCC"/><input type= "Radio" Name= "a" value= "ACCC"/>
<input type= "Radio" name= "B" value= "BCCC"/><input type= "Radio" name= "B" value= "BCCC"/><input type= " Radio "Name=" "B" value= "BCCC"/>
<input type= "Radio" name= "C" checked=checked value= "ceee"/><input type= "Radio" name= "C" value= "Ceee"/> <input type= "Radio" name= "C" value= "Ceee"/>
<input type= "Radio" name= "D" checked=checked value= "DFFF"/><input type= "Radio" name= "D" value= "Dfff"/> <input type= "Radio" name= "D" value= "Dfff"/>
<input type= "Radio" Name= "E" checked=checked value= "ehhh"/><input type= "Radio" Name= "E" value= "Ehhh"/> <input type= "Radio" Name= "E" value= "Ehhh"/>
</body>
<script>
function Check () {
var mm=document.getelementsbytagname ("input");
var mask=0;
var temp=[];
var temp1=[];
if (mm.lenght<1) {alert (' err ');}
else{
for (i=0;i<mm.length;i++) {
if (mm[i].type== "Radio" &&mm[i].checked==true) {
Temp.push (Mm[i].value)
mask++;
}
else if (mm[i].type== "Radio" &&mm[i].checked==false) {
Temp1.push (Mm[i].value)
}
}
Alert ("Selected" +temp+ "N is not selected" +TEMP1);
if (mask==0) {alert (' no checked ')}
}
}
Check ();
</script>
Change automatic selection to single selection
<lable>
<input type= "Radio" name= "a"/> The <input type= "Radio" name= "a"/> <input type= "Radio" name= "a"/> <inpu T type= "Radio" name= "a"/>
</lable>
<br/>
<lable>
<input type= "Radio" name= "B"/> <input "type=" Radio "" B "name=/> <input" type= "Radio" B "name=/> T type= "Radio" name= "B"/>
</lable>
<br/>
<lable>
<input type= "Radio" name= "C"/> <input "type= Radio" name= "C"/> <input type= "Radio" name= "C"/> <inpu T type= "Radio" name= "C"/>
</lable>
<div><button onclick= "Checkradio ()" >checkall</button></div>
<script type= "text/web Effects" >
function Checkradio ()
{
var inputs = document.getElementsByTagName ("input");
var radios = [];
for (Var i=0,l=inputs.length;i<l;i++)
{
if (inputs[i].type== "Radio" && Inputs[i].name)
Radios.push (Inputs[i]);
}
var hash= {};
for (Var i=0,l=radios.length;i<l;i++)
{
if (!hash[radios[i].name])
Hash[radios[i].name] = [Radios[i]]
Else
Hash[radios[i].name].push (Radios[i]);
}
for (var i in hash)
{
var iflag = false;
for (Var j=0,l=hash[i].length;j<l;j++)
{
if (hash[i][j].checked)
{
Iflag = true;
Break
}
}
if (!iflag)
{
Alert ("Name +i+") has not been selected for this set of radio boxes! ");
return false;
}
}
Alert ("Congratulations,all pass!");
return true;
}
</script>