In order to correct the submission of the form, before the submission will be the form of each item validation, today brings is using JavaScript for radio validation, to determine the number of radio box, which is selected, or to remove its value, the following HTML code, including JS parts:
The code is as follows |
Copy Code |
<HTML> <script language= "VBScript" > function Checkme () For each OB in Radio1 If Ob.checked Then Window.alert Ob.value Next End Function </script> <BODY> <input name= "Radio1" type= "Radio" value= "/style" Checked>style <input name= "Radio1" type= "Radio" value= "/test" >barcode <input type= "button" value= "Check" onclick= "Checkme ()" > </BODY> </HTML> |
This function returns the selected radio value and verifies which radio is selected.
Example 2
The code is as follows |
Copy Code |
<TITLE>JS Determine if Radio radio button is selected </title> <script type= "Text/javascript" > function Validateradio () { var radioselete = "Nothing"; var Seletedvalue; for (i=0;i<document.form1.rvalue.length;i++) { if (document.form1.rvalue[i].checked) { Radioselete = "seleted"; Seletedvalue = Document.form1.rvalue[i].value; } } if (Radioselete = "Nothing") { Alert ("Please select a place name.") "); return false; } Else { Alert ("You selected is:" +seletedvalue); return true; } } </script> <body> <form name= "Form1" > <input type= "Radio" name= "RValue" value= "Sichuan" > Sichuan <input type= "Radio" name= "RValue" value= "Jiangsu" > Jiangsu <input type= "Radio" name= "RValue" value= "Nanjing" > Nanjing <input type= "Radio" name= "RValue" value= "Tianjin" > Tianjin <input type= "Radio" name= "RValue" value= "Shanghai" > Shanghai <input type= "button" onclick= "Return Validateradio ()" value= "Authentication" > </form> </body> |