{"id":509,"date":"2012-01-11T22:46:12","date_gmt":"2012-01-11T17:46:12","guid":{"rendered":"http:\/\/www.esearing.com\/v2010\/?p=509"},"modified":"2012-01-11T22:46:12","modified_gmt":"2012-01-11T17:46:12","slug":"javascript-toggle-all-checkboxes","status":"publish","type":"post","link":"https:\/\/www.esearing.com\/v2010\/2012\/01\/javascript-toggle-all-checkboxes\/","title":{"rendered":"Javascript Toggle All Checkboxes"},"content":{"rendered":"<p>Here is a nifty little tool I modified to toggle all checkboxes on a page. I use this when displaying a list of files or items that need to be processed on form submit. <\/p>\n<p><code><br \/>\n&lt;SCRIPT LANGUAGE=\"JavaScript\"&gt<br \/>\n\/\/Toggle all Checkboxes<br \/>\nfunction toggle_all(x){<br \/>\n\t\/\/alert('toggle = '+ x);<br \/>\n\tvar inputlist = document.getElementsByTagName(\"input\");<br \/>\n\tfor (i = 1; i < inputlist.length; i++) {\n\t\tif ( inputlist[i].getAttribute(\"type\") == 'checkbox' ) { \/\/ look only at input elements that are checkboxes\n\t\t\tif (x == false) inputlist[i].checked = false\n\t\t\telse inputlist[i].checked = true;\n\t\t\t}\n\t\t}\n\t}\n\n&lt;\/script&gt;\n\nPut this above the list of items that have a checkbox. Notice that above I start the counter at 1 rather than zero so it ignores this checkbox.\n&lt;input type=\"checkbox\" name=\"togall\" onclick=\"javascript: toggle_all(this.checked);\"&gt;\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a nifty little tool I modified to toggle all checkboxes on a page. I use this when displaying a list of files or items that need to be processed on form submit. &lt;SCRIPT LANGUAGE=&#8221;JavaScript&#8221;&#038;gt \/\/Toggle all Checkboxes function &hellip; <a href=\"https:\/\/www.esearing.com\/v2010\/2012\/01\/javascript-toggle-all-checkboxes\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,12,24],"tags":[],"class_list":["post-509","post","type-post","status-publish","format-standard","hentry","category-code","category-javascript","category-snippets-quick-code-tips-for-single-elements-attributes-or-details"],"_links":{"self":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/comments?post=509"}],"version-history":[{"count":2,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/509\/revisions"}],"predecessor-version":[{"id":511,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/509\/revisions\/511"}],"wp:attachment":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/media?parent=509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/categories?post=509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/tags?post=509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}