The Document.getelementsbyname (name) method is used to read an array of objects. Usage is as follows:
var elements = document.getelementsbyname ("role");
("Role" is the common name for each checkbox in the checkbox array)
for:
<ptml> <pead> <meta http-equiv= "Content-type" Content= "text/html; charset=gb2312 "/> <title>getelementsbyname paradigm </title> <script type=" Text/javascript "> function Test () {//Get checkbox array var elements = Document.getelementsbyname ("role"); var str = ""; Gets 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 ("The role you selected is: \ n \ nthe" + str); } </script> </pead> <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 Nam e= "Role" type= "checkbox" value= "System Administrator" > General manager <input name= "role" type= "checkbox" value= "General Manager" > Agent <input Nam e= "Role" type= "checkbox" value= "Agent" > Customer service staff <input name= "role" type= "checkbox" value= "Customer Service Personnel" > </td> </tr> <tr> <td height= "colspan=" "2" align= "Center" &G T <input type= "button" id= "btnsubmit" value= "Output selection result" onclick= "test ();"/> </tr> </table> </body> </ptml>
[ctrl+a All selected note: If you need to introduce external JS need to refresh to perform]