How does JavaScript get the value of input type = "radio?
Source: Internet
Author: User
< Script Language = " Javascript " >
<! --
Function Chk () {
VaR OBJ = Document. getelementsbyname ( ' Imgposition ' );
For (I = 0 ; I < OBJ. length; I ++ ) {
If(OBJ [I]. Checked){
Alert (OBJ [I]. value );
Return;
}
}
Alert ( ' You did not select ' );
}
// -->
< / SCRIPT>
< Form name = Form1 >
< Input type = " Radio " Name = " Imgposition " Value = " 1 " >
< Input type = " Radio " Name = " Imgposition " Value = " 2 " >
< Input type = " Radio " Name = " Imgposition " Value = " 3 " >
< / Form>
< Input type = " Button " Onclick = " Chk () " >
For Example:
< Input type = Radio name = " Radio " Checked > 1 - 10 Years Old
< Input type = Radio name = " Radio " > 11 Years Old
< Input type = Radio name = " Radio " > 12 - 120 Years Old
This example uses script to detect which radio button the user selects.
< Script >
Function Detect ()
{
If (Radio [ 0 ]. Checked)
Alert ( " You're between 1 and 10 years old. " )
Else If (Radio [ 1 ]. Checked)
Alert ( " You're 11 years old. " )
Else
Alert ( " You're between 12 and 120 years old. " )
}
< / SCRIPT>
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