How to check all check box By clicking one checkbox

Js

Posted on 30 Jan 15 by Vickey
  678



I have html table of users with a checkbox for each row. i want check all checkbox by clicking on checkbox on the top

<form id="form">
<table>
	<tbody>
		<tr>
			<th><input type="checkbox" onclick="checkedAll();" /></th>
			<th>Name></th>
			<th>>Phone</th>
		</tr>
		<tr>
			<td><input type="checkbox" /></td>
			<td>Ram</td>
			<td>6456456464</td>
		</tr>
		<tr>
			<td><input type="checkbox" /></td>
			<td>Ram</td>
			<td>6456456464</td>
		</tr>
	</tbody>
</table>

 

for check all checkbox i used js code by using form id

checked = false;
     function checkedAll ()
        {
        if (checked == false)
            {
            checked = true
            }
        else
            {
            checked = false
            }
    for (var i = 0; i < document.getElementById("form").elements.length; i++)
        {
        document.getElementById("form").elements[i].checked = checked;
        }
      }

If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com