Compare full JS checkbox Select All, deselect all, delete function code

Source: Internet
Author: User

Look at the following two ways to implement: JS checkbox method One:

Copy CodeThe code is as follows: function Checkall () {var code_values = document.all[' Code_value '); if (code_values.length) {
for (Var i=0;i<code_values.length;i++) {code_values[i].checked = true;}} else{code_values.checked = True;}} function Uncheckall () {var code_values = document.all[' Code_value '];
if (code_values.length) {for (Var i=0;i<code_values.length;i++) {
code_values[i].checked = false; }}else{code_values.checked = false;}} function Multipledelete () {var num = 0; var code_values = document.all[' Code_value ']; if (code_values.length) {
for (Var i=0;i<code_values.length;i++) {if (code_values[i].checked = = true) {num + +;}}} else{if (code_values.checked = = true) {num + +;}} if (num = = 0) {alert (' Please select Delete item ');} if (num >0) {doc Ument. Bucodesearch.action = ' <%=eusutil.getpage ("lookup.generic.bucode.delete.s")%> ';
Document. Bucodesearch.submit (); }} </script>

JS checkbox Method Two:

Copy CodeThe code is as follows: function Checkall () {var code_values = document.getelementsbytagname ("input"); for (i = 0;i < code_values.length; i++) {if (Code_values[i].type = = "checkbox") {
Code_values[i].checked = true; }}} function Uncheckall ()
{var code_values = document.getelementsbytagname ("input"); for (i = 0;i < code_values.length;i++) {if (Code_values[i]. Type = = "checkbox")
{code_values[i].checked = false;} }} function Multipledelete () {if (document. bucodesearch.elements["Code_value"])
{var num = 0; var fm = document. Bucodesearch; if (document. bucodesearch.elements["Code_value"]) {var elm = document. bucodesearch.elements["Code_value"]; var ename = "Code_value";
if (elm.length) {var len = fm.elements[ename].length; for (var i = 0; i< len; i++) {var e = fm.elements[ename][i]; if (e.checked = = True) {num++;} }} else {if (elm.checked = = True) {
num++; }} if (num > 0) {
Document. Bucodesearch.action = ' <%=eusutil.getpage ("lookup.generic.bucode.delete.s")%> ';
Document. Bucodesearch.submit (); } } } }

Code_value is the name of the checkbox form and Bucodesearch is the form name

Copy CodeThe code is as follows: <td align= "left" width= "><input type=" checkbox "Name=" Code_value "value=" <%= Userdeffieldvaluebean.getudfvalue ()%> "></td>

Compare full JS checkbox Select All, deselect all, delete function code

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.