Skip to content

Instantly share code, notes, and snippets.

@AlexanderMike
Last active March 1, 2016 17:09
Show Gist options
  • Select an option

  • Save AlexanderMike/059d696489d2ca16ae7f to your computer and use it in GitHub Desktop.

Select an option

Save AlexanderMike/059d696489d2ca16ae7f to your computer and use it in GitHub Desktop.
http://stackoverflow.com/questions/10908212/select-all-checkbox-by-javascript-or-console
var allInputs = document.getElementsByTagName("input");
for (var i = 0, max = allInputs.length; i < max; i++){
if (allInputs[i].type === 'checkbox')
allInputs[i].checked = true;
}
<!--http://www.webdevdoor.com/javascript-ajax/javascript-function-check-uncheck-checkboxes-->
<script type="text/javascript" language="javascript">// <![CDATA[
function checkAll(formname, checktoggle)
{
var checkboxes = new Array();
checkboxes = document[formname].getElementsByTagName('input');
for (var i=0; i<checkboxes.length; i++) {
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = checktoggle;
}
}
}
// ]]></script>
<a onclick="javascript:checkAll('form3', true);" href="javascript:void();">check all</a>
<a onclick="javascript:checkAll('form3', false);" href="javascript:void();">uncheck all</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment