Skip to content

Instantly share code, notes, and snippets.

@EdgeCaseBerg
Created December 30, 2013 05:14
Show Gist options
  • Select an option

  • Save EdgeCaseBerg/8178096 to your computer and use it in GitHub Desktop.

Select an option

Save EdgeCaseBerg/8178096 to your computer and use it in GitHub Desktop.
Simple javascript to ensure that checkboxes act in an incremental fashion. If checkbox 5 is clicked, then ALL checkboxes up to 5 will be checked, if checkbox 2 is unchecked, then all checkboxes after 2 will be unchecked as well.
<script type="text/javascript">
/* Javascript to force incremental changes
* If checkbox 1,2, 5 are checked then all
* migrations 1,2,3,4,5 should be applied.
* If checkbox 3 is unchecked, all checkboxes
* after 3 should be unchecked as well.
*/
var inputs = document.getElementsByName("migrations[]");
for (var i = inputs.length - 1; i >= 0; i--) {
inputs[i].onclick = function(evt){
var parentTr = this.parentNode.parentNode.parentNode;
if( this.checked ){
/* Find and set the previous children to true*/
while(parentTr){
parentTr.firstChild.firstChild.firstChild.checked = true;
parentTr = parentTr.previousElementSibling;
}
}else{
/* Find and set the future children to false */
while(parentTr){
parentTr.firstChild.firstChild.firstChild.checked = false;
parentTr = parentTr.nextElementSibling;
}
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment