Created
December 30, 2013 05:14
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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