Put the radio input in the form,
<form name=theform>
<input type=text name=input1 value= "Test" >
<input type=radio name= "a[]" value= "0" checked> option 1
<input type=radio name= "a[]" value= "1" > option 2
</form>
Instance 1
==javascript read the value of radio = =
The code is as follows |
Copy Code |
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 ("Radio box unchecked"); return false; } </script> |
Instance 2
The user clicks the current radio implementation to read the current radio value
The code is as follows |
Copy Code |
<script type= "Text/javascript" language= "JavaScript" > function Permissions (obj) { var radioss= obj.value alert (Radioss); } </script> <body> <input type= "Radio" id= "Radios" name= "radios" value= "0" onclick= "Permissions (This)" >admin <input type= "Radio" id= "Radios" name= "Radios" value= "1" onclick= "Permissions (This)" >user |
Instance 3
= = Set Radio which is selected = =
The code is as follows |
Copy Code |
<script> function Setradio (v) { Robj=document.form1.radioname; for (i=0;i<robj.length;i++) { if (robj[i].value==v) { Robj[i].checked=true; } } } </script> |
Edit summary:
The most important thing we see is
The code is as follows |
Copy Code |
if (formobj.a[i].checked) { Alert ("Select box selected: + Formobj.a[i].value"); return true; } |
FORMOJB is the name of the form we want to define, this must be the same as in JS, and then A is our multiple radio named a[] This form, a[i] refers to the radio of the first few Formobj.a[i].value The key to this is to get the value in the Formobj.a[i].value.