How to select all check boxes in JS and select all check boxes in js
The Code is as follows:
<? Include_once ("inc/auth. inc. php"); include_once ("inc/utility_all.php"); include_once ("inc/utility_org.php"); $ connstatus = ($ connstatus )? True: false; if (! Isset ($ TYPE) $ TYPE = "0"; $ ITEMS_IN_PAGE = 10; if (! Isset ($ start) | $ start = "") $ start = 0; $ HTML_PAGE_TITLE = _ ("File Management"); include_once ("inc/header. inc. php ");?> <Script> function open_file (FILE_ID) {URL = "read_file.php? FILE_ID = "+ FILE_ID; myleft = (screen. availWidth-500)/2; mytop = 150 mywidth = 550; myheight = 300; window. open (URL, "read_file", "height =" + myheight + ", width =" + mywidth + ", status = 1, toolbar = no, menubar = no, location = no, scrollbars = yes, top = "+ mytop +", left = "+ myleft +", resizable = yes ");} function delete_file (FILE_ID, CUR_PAGE) {msg = '<? = _ ("Are you sure you want to destroy this file? ")?> '; If (window. confirm (msg) {URL = "delete. php? FILE_ID = "+ FILE_ID +" & CUR_PAGE = "+ CUR_PAGE; window. location = URL ;}} function delete_all () {delete_str = ""; for (I = 0; I <document. getElementsByName ("file_select "). length; I ++) {el = document. getElementsByName ("file_select "). item (I); if (el. checked) {val = el. value; delete_str + = val + "," ;}} if (I = 0) {el = document. getElementsByName ("file_select"); if (el. checked) {val = el. value; delete_str + = val + ",";}} If (delete_str = "") {alert ("<? = _ ("To destroy a file, select at least one of them. ")?> "); Document. form1.reset (); return;} msg = '<? = _ ("Are you sure you want to destroy the selected files? ")?> '; If (window. confirm (msg) {url = "./delete_all.php? DELETE_STR = "+ delete_str +" & PAGE_START = <? = $ PAGE_START?> "; Window. location = url;} function order_by (field, asc_desc) {window. location =" index1.php? CUR_PAGE = <? = $ CUR_PAGE?> & Amp; TYPE = <? = $ TYPE?> & FIELD = "+ field +" & ASC_DESC = "+ asc_desc;} function file_troop (type) {document. form1.action =" troop. php? CUR_PAGE = <? = $ CUR_PAGE?> & FIELD = <? = $ FIELD?> & ASC_DESC = <? = $ ASC_DESC?> "; Document.form1.tar get = '_ self'; document. form1.submit ();} function check_all () {for (I = 0; I <document. getElementsByName ("file_select "). length; I ++) {if (document. getElementsByName ("allbox") [0]. checked) document. getElementsByName ("file_select "). item (I ). checked = true; else document. getElementsByName ("file_select "). item (I ). checked = false;} if (I = 0) {if (document. getElementsByName ("allbox") [0]. checked) Document. getElementsByName ("file_select "). checked = true; else document. getElementsByName ("file_select "). checked = false ;}} function change_roll () {delete_str = ""; for (I = 0; I <document. getElementsByName ("file_select "). length; I ++) {el = document. getElementsByName ("file_select "). item (I); if (el. checked) {val = el. value; delete_str + = val + "," ;}} if (I = 0) {el = document. getElementsByName ("file_select"); if (El. checked) {val = el. value; delete_str + = val + "," ;}} var myselect = document. getElementById ("SROLL_ID"); var index = myselect. selectedIndex; if (delete_str = "") {alert ("<? = _ ("Select at least one of the exam papers. ")?> "); Document. form1.reset (); return;} roll_id = myselect. options [index]. value; url ="./change_roll.php? DELETE_STR = "+ delete_str +" & ROLL_ID = "+ roll_id +" & PAGE_START = <? = $ PAGE_START?> "; Location = url;} function check_one (el) {if (! El. checked) document. getElementsByName ("allbox") [0]. checked = false;} function shenpi_all () {delete_str = ""; for (I = 0; I <document. getElementsByName ("file_select "). length; I ++) {el = document. getElementsByName ("file_select "). item (I); if (el. checked) {val = el. value; delete_str + = val + "," ;}} if (I = 0) {el = document. getElementsByName ("file_select"); if (el. checked) {val = el. value; delete_str + = val + ",";}} If (delete_str = "") {alert ("<? = _ ("To approve a file, select at least one of them. ")?> "); Document. form1.reset (); return;} msg = '<? = _ ("Are you sure you want to approve the selected file? ")?> '; If (window. confirm (msg) {// alert (delete_str); url = "./shenpi_all.php? SHENPI_STR = "+ delete_str +" & start = <? = $ Start?> "; Window. location = url ;}</script> <body class =" bodycolor "><? // $ Query = "SELECT count (*) from RMS_FILE_NEW, RMS_ROLL, RMS_ROLL_ROOM where RMS_FILE_NEW.ROLL_ID = RMS_ROLL.ROLL_ID and RMS_ROLL.ROOM_ID = between and between = '". $ _ SESSION ["LOGIN_USER_ID"]. "'and RMS_FILE_NEW.DEL_USER ='' and SHENPISTATUS = '1' "; $ query =" SELECT count (*) from RMS_FILE_NEW where RMS_FILE_NEW.shenpiren = '". $ _ SESSION ["LOGIN_USER_ID"]. "'and RMS_FILE_NEW.DEL_USER = ''And SHENPISTATUS = '1'"; // echo $ query. "<br>"; if ($ TYPE! = "0") $ query. = "and CATALOG_NO = '$ type'"; // echo $ query. "<br>"; $ cursor = exequery (TD: conn (), $ query, $ connstatus); $ RMS_FILE_NEW_COUNT = 0; if ($ ROW = mysql_fetch_array ($ cursor) $ RMS_FILE_NEW_COUNT = $ ROW [0]; if ($ RMS_FILE_NEW_COUNT = 0) {?> <Table border = "0" width = "100%" cellspacing = "0" cellpadding = "3" class = "small"> <tr> <td class = "Big"> /Static/images/notify_open.gif "align =" absmiddle "> <span class =" big3 "> <? = _ ("Pending approval document")?> </Span> </td> </tr> </table> <br> <? Message ("", _ ("no file to be approved"); exit ;}?> <Table border = "0" width = "100%" cellspacing = "0" cellpadding = "3" class = "small"> <tr> <td class = "Big"> /Static/images/notify_open.gif "align =" absmiddle "> <span class =" big3 "> <? = _ ("File Management pending approval")?> </Span> </td> <td align = "right" valign = "bottom" class = "small1"> <? = Sprintf (_ ("% s total"), '<span class = "big4">'. $ RMS_FILE_NEW_COUNT. '</span>')?> </Td> <td align = "right" valign = "bottom" class = "small1"> <? = Page_bar ($ start, $ RMS_FILE_NEW_COUNT, $ ITEMS_IN_PAGE)?> </Td> </tr> </table> <? If ($ ASC_DESC = "") $ ASC_DESC = "1"; // if ($ FIELD = "") // $ FIELD = "FILE_CODE "; // =========================================== show published files ======== ======================================= // $ query = "SELECT * from RMS_FILE_NEW, RMS_ROLL, RMS_ROLL_ROOM where RMS_FILE_NEW.ROLL_ID = RMS_ROLL.ROLL_ID and RMS_ROLL.ROOM_ID = RMS_ROLL_ROOM.ROOM_ID and RMS_FILE_NEW.shenpiren = '". $ _ SESSION ["LOGIN_USER_ID"]. "'and RMS_FILE_NEW.DEL_USER ='' and SHENPI STATUS = '1' "; $ query =" SELECT * from RMS_FILE_NEW where RMS_FILE_NEW.shenpiren = '". $ _ SESSION ["LOGIN_USER_ID"]. "'and RMS_FILE_NEW.DEL_USER ='' and SHENPISTATUS = '1' "; // echo $ query1." <br> "; if ($ FIELD =") {$ query. = "order by RMS_FILE_NEW.ADD_TIME DESC, RMS_FILE_NEW.MOD_TIME DESC";} else {$ query. = "order by $ FIELD"; if ($ ASC_DESC = "1") $ query. = "desc"; else $ query. = "asc";} // echo $ query; $ quer Y. = "limit $ start, $ ITEMS_IN_PAGE"; if ($ ASC_DESC = "0") $ ORDER_IMG = " "; else $ ORDER_IMG = " ";?> <Table class = "TableList" width = "100%"> <form action = "? "Method =" post "name =" form1 "> <tr class =" TableHeader "> <td nowrap align =" center "> <input type =" checkbox "name =" allbox ""id =" allbox_for "onClick =" check_all (); "> </td> <td nowrap align =" center "onClick =" order_by ('file _ Code', '<? If ($ FIELD = "FILE_CODE") echo 1-$ ASC_DESC; else echo "1";?> '); "Style =" cursor: hand; "> <u> <? = _ ("File number")?> </U> <? If ($ FIELD = "FILE_CODE") echo $ ORDER_IMG;?> </Td> <td nowrap align = "center" onClick = "order_by ('file _ title', '<? If ($ FIELD = "FILE_TITLE") echo 1-$ ASC_DESC; else echo "1";?> '); "Style =" cursor: hand; "> <u> <? = _ ("File title")?> </U> <? If ($ FIELD = "FILE_TITLE") echo $ ORDER_IMG;?> </Td> <td nowrap align = "center"> <? = _ ("Confidentiality")?> </Td> <td nowrap align = "center" onClick = "order_by ('send _ part', '<? If ($ FIELD = "SEND_UNIT" | $ FIELD = "") echo 1-$ ASC_DESC; else echo "1";?> '); "Style =" cursor: hand; "> <u> <? = _ ("Issuer")?> </U> <? If ($ FIELD = "SEND_UNIT" | $ FIELD = ") echo $ ORDER_IMG;?> </Td> <td nowrap align = "center" onClick = "order_by ('send _ date', '<? If ($ FIELD = "SEND_DATE") echo 1-$ ASC_DESC; else echo "1";?> '); "Style =" cursor: hand; "> <u> <? = _ ("Posting time")?> </U> <? If ($ FIELD = "SEND_DATE") echo $ ORDER_IMG;?> </Td> <td nowrap align = "center"> <? = _ ("File")?> </Td> <td nowrap align = "center"> <? = _ ("Creator")?> </Td> <td nowrap align = "center"> <? = _ ("Operation")?> </Td> </tr> <? $ Cursor = exequery (TD: conn (), $ query, $ connstatus); $ RMS_FILE_NEW_COUNT = 0; while ($ ROW = mysql_fetch_array ($ cursor )) {$ RMS_FILE_NEW_COUNT ++; $ FILE_ID = $ ROW ["FILE_ID"]; $ FILE_CODE = $ ROW ["FILE_CODE"]; $ FILE_TITLE = $ ROW ["FILE_TITLE"]; $ SECRET = $ ROW ["SECRET"]; $ SEND_UNIT = $ ROW ["SEND_UNIT"]; $ SEND_DATE = $ ROW ["SEND_DATE"]; $ URGENCY = $ ROW ["URGENCY"]; $ ROLL_ID = $ ROW ["ROLL_ID"]; $ ADD_USER = $ ROW ["ADD_USER"]; $ ADD_TIME = $ ROW ["ADD_TIME"]; $ query1 = "SELECT * from RMS_ROLL where ROLL_ID = '$ ROLL_ID'"; $ cursor1 = exequery (TD: conn (), $ query1 ); if ($ ROW = mysql_fetch_array ($ cursor1) {$ ROLL_NAME = $ ROW ["ROLL_NAME"]; $ STATUS = $ ROW ["STATUS"];} else {$ ROLL_NAME = "";} if ($ SEND_DATE = '2017-00-00 ') $ SEND_DATE = ''; $ FILE_TITLE = htmlspecialchars ($ FILE_TITLE ); $ SECRET = get_code_name ($ SECRET, "RMS_SECRET"); $ URGENCY = get_code_name ($ URGENCY, "RMS_URGENCY"); if ($ RMS_FILE_NEW_COUNT % 2 = 1) $ TableLine = "TableLine1"; else $ TableLine = "TableLine2";?> <Tr class = "<? = $ TableLine?> "> <Td nowrap align =" center "> <? If ($ STATUS! = 1) {?> <Input type = "checkbox" name = "file_select" value = "<? = $ FILE_ID?> "OnClick =" check_one (self); "> </td> <?} Else echo "";?> <Td align = "center" nowrap> <a href = "javascript: open_file ('<? = $ FILE_ID?> '); "> <? = $ FILE_CODE?> </A> </td> <td align = "center"> <a href = "javascript: open_file ('<? = $ FILE_ID?> '); "> <? = $ FILE_TITLE?> </A> </td> <td nowrap align = "center"> <? = $ SECRET?> </Td> <td nowrap align = "center"> <? = $ SEND_UNIT?> </Td> <td nowrap align = "center"> <? = $ SEND_DATE?> </Td> <td nowrap align = "center"> <? = $ ROLL_NAME?> </Td> <td nowrap align = "center"> <? = Substr (getUserNameById ($ ADD_USER), 0,-1);?> </Td> <td nowrap align = "center"> <? If ($ STATUS! = 1) {?> <A href = "modify. php? FILE_ID = <? = $ FILE_ID?> & Amp; start = <? = $ Start?> "> <? = _ ("Approval")?> </A> <?} Else echo _ ("file closed");?> <A href = "javascript: delete_file ('<? = $ FILE_ID?> ',' <? = $ CUR_PAGE?> '); "> <? = _ ("Destroy")?> </A> </td> </tr> <? }?> <Tr class = "TableControl"> <td colspan = "9"> <B> <? = _ ("File operation:")?> </B> <input type = "button" value = "<? = _ ("Batch destruction")?> "Class =" SmallButton "onClick =" delete_all () "title =" <? = _ ("Destroy selected files")?> "> <Input type =" button "value =" <? = _ ("Batch approval")?> "Class =" SmallButton "onClick =" shenpi_all () "title =" <? = _ ("Batch approve selected files")?> "> </Td> </tr> </form> </table> </body>
The above section describes how to select all the check boxes in Javascript. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!