Check all checkboxes inside page using JavaScript

One requirement came recently where we need to check all the checkboxes inside the page. So here we will discuss how we can check or uncheck all the checkboxes using javascript



You may also like:



Check all Checkboxes:
<input type='button' id='1234' value='Check All' onclick="checkAllItems();"/>

<script language="javascript" type="text/javascript">
function checkAllItems() {
var tags = document.getElementsByTagName("input");
for (var i =0; i < tags.length; i++){
if (tags[i].type == 'checkbox')
tags[i].checked = true;
}
}
</script>

UnCheck All Checkboxes:
<input type='button' id='4321' value='Check All' onclick="uncheckAllItems();"/>

<script language="javascript" type="text/javascript">
function uncheckAllItems() {
var tags = document.getElementsByTagName("input");
for (var i =0; i < tags.length; i++){
if (tags[i].type == 'checkbox')
tags[i].checked = false;
}
}
</script>
Hope this will work.


Origin:  
http://www.enjoysharepoint.com/DotNet/d/check-all-checkboxes-inside-page-using-javascript-411.aspx
Twitter: marceloperez07

Comentarios

Entradas populares de este blog

AZURE