Checkbox select using querySelectorAll is not working

checkbox, html, javascript

Solution

Try any other name for function `select`, rest your code is fine.

Problem

I have the following code, mostly from How can I select all checkboxes from a form using pure JavaScript and it's just not working. Test.html ``` <html> <head> <script> function select(){ var inputs = document.querySelectorAll("input[type='checkbox']"); for(var i = 0; i < inputs.length; i++) { inputs[i].checked = true; } } </script> </head> <body> <form id="myId" name="myForm"> <input type="checkbox" value="1"/> 1 <input type="checkbox" value="2"/> 2 <input type="checkbox" value="3"/> 3 <input type="button" onclick="select()" value="Select all"/> </form> </body> </html> ``` Clicking the button does nothing. I must be doing something really wrong here but I just can't pick it out.

Original source

Related problems