JavaScript determines whether a radio box or check box is selected method Collection _ form Effects

Source: Internet
Author: User
Tip: The purpose of the Getemementsbyname method is to get a collection of objects based on the value of the NAME tag property.
Sample One <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Determine if the Radio box or check box is selected </title>

<body>
<input name= "Radio1" type= "Radio" value= "Test" >
<button onclick= "alert" (' Single option ' + (document.getelementsbyname (' Radio1 ') [0].checked? ": ' no ') + ' selected '" > Test </button><br>
<input name= "Radio1" type= "Radio" value= "Test" >
<button onclick= "alert" (' Single option ' + (document.getelementsbyname (' Radio1 ') [1].checked? ': ' No ') + ' selected ') ' > Test </ Button><br>

<input name= "CheckBox1" type= "checkbox" value= "Test" >
<button onclick= "alert" (' Multiple options ' + (Document.getelementsbyname (' CheckBox1 ') [0]. Checked? ': ' No ') + ' selected ') ' > Test </ Button><br>
<input name= "CheckBox1" type= "checkbox" value= "Test" >
<button onclick= "alert" (' Multiple options ' + (Document.getelementsbyname (' CheckBox1 ') [1].checked? ': ' No ') + ' selected ') ' > Test </ Button>

Tip: The purpose of the Getemementsbyname method is to get a collection of objects based on the value of the NAME tag property.
</body>
Sample two:

<form name= "MyForm" action= "method=" "onsubmit=" return Check () ">
<input type= "Radio" name= "Picno" value= "1" >
<input type= "Radio" name= "Picno" value= "2" >
<input type= "Radio" name= "Picno" value= "3" >
<input type= "Submit" value= "Submit" >
</form>
<script language= "JavaScript" ....
function Check () ... {
var flag=0
for (i=0;i<myform.picno.length;i++)
if (myform.picno[i].checked==true) ... {
Flag=1
Break
}
if (!flag) ... {
Alert ("Choose where to replace the picture first")
return False
}
}
</script>

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.