Script for Select All checkboxes not working on WordPress page

I’m trying to create checkboxes with a Select All checkbox in a normal WordPress page using a Text block.

Here’s my code:

Read More
<script type="text/javascript">
alert('hey');
function toggle(source) {
  checkboxes = document.getElementsByName('options');
  for(var i=0, n=checkboxes.length;i<n;i++) {
    checkboxes[i].checked = source.checked;
  }
}
</script>

<form>
<input type="checkbox" value="All" onClick="toggle(this)" />All
<input type="checkbox" class="checkbox1" name="options" value="Option1" id="opt1">Option 1
<input type="checkbox" class="checkbox1" name="options" value="Option2" id="opt2">Option 2
<input type="checkbox" class="checkbox1" name="options" value="Option3" id="opt3">Option 3
</form>

The alert shows up. But the function Check All is not working. I tried it on a Notepad, and it’s working. But in a WordPress page, it’s not.

Please help. Thanks!

Related posts

Leave a Reply

2 comments

  1. Hmm. I tested it on my wordpress page, and it worked. what version are you using? Did you paste the code into the page using the “text” tab activated?