Skip to content

Month: July 2013

How to create a ‘select all’ checkbox in javascript

For HTML Code:

<input type="checkbox" onClick="toggle(this)" />

<input type='checkbox' name='ss' value='one'  />
<input type='checkbox' name='ss' value='two'  />
<input type='checkbox' name='ss' value='three'  />

We use Javascript:

  function toggle(source) {
    checkboxes = document.getElementsByName('ss');
    for (var i = 0, n = checkboxes.length; i < n; i++) {
      checkboxes[i].checked = source.checked;

How to add hidden fields to form and submit with Javascript

In HTML Code: <form action=’myScript.php’ method=’get’ name=’myForm’> </form> Javascript code: var form = document.forms[‘myForm’]; // form.action = ‘put your url here’; var na = document.createElement(“input”); na.type = “hidden”; = “name”; na.value = “Bob The Builder”; form.appendChild(na); form.submit();