JS detection Radio The selection box is selected

Source: Internet
Author: User

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

&LT;TITLE&GT;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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.