Practical JS Get CheckBox value Code

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax checkbox code content customer service get html http

 
<html>
<head>
<meta http-equiv= "Content-type content=" html gb2312 "/>
<title>getelementsbyname example </title>
<script type=" Text/javascript ">
function test () {
//Get checkbox array
var elements = document.getelementsbyname ("role");
var str = "";
//Get the selected role
for (Var i=0;i<elements.length;i++) {
if (elements[i].checked) {
str + + > + elements[i] . Value + "n";
}
}
//Output
if (str = "") {
Alert ("You did not select any role!") ");
}
else{
Alert (Your selected role is: NN + str);
}


</script> </head>
<body>
<table cellspacing= "5" cellpadding= "2" align = "Center" border= "1" >
<tr>
<td align= "center" class= "Dgheader" nowrap> Select role </td>
< TD align= "Left" >
system Administrator <input name= "role" type= "checkbox" value= "system administrator"
 
General manager <input Name= "Role" type= "checkbox" value= "General manager" >
 
Agent <input name= "role" type= "checkbox" value= "Agent"
 
Customer service <input name= "role" type= "checkbox" value= "Customer service personnel"
 
</td>
</tr>
<tr>
<td height= "colspan=" 2 "align= Center" >
<input type= "button" id= "Btnsubmit" style= "font-size:12px;width:90px" value= "Output selection Results" onclick= "Test ();"/>
</tr>
</table>
</body>
</html>

Related Article

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.