html - SelectAll button using JavaScript -


I have the following code. I want to check all the check boxes on the button click. How can I do this using Javascript?

  & lt; Div id = "blocked_list_add_website_help_text" & gt; & Lt; Button type = "button" id = "blockSelectall" class = "secondary" & gt; Select all & lt; / Button & gt; & Lt; / Div & gt; & Lt; Input type = "checkbox" value = "box 1" /> Box 1 & lt; Input type = "checkbox" value = "box 2" /> box 2 < Input type = "checkbox" value = "box 3" /> Box 3    

Pure JS:

  document. getElementById ("BlockSelectAll"). Onclick = function () {var inputs = document.getElementsByTagName ("input"); (Var i = 0; i & lt; inputs.length; i ++) {if (input [i] .type == "checkbox") {inputs [i]. Checkeded = true; }}}   



Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -