Last active
December 20, 2015 05:59
-
-
Save valdiney/c5764a525d842bffa90c to your computer and use it in GitHub Desktop.
Submete um formulário assim que dois checkboxs sejam selecionados
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> | |
window.onload = function() { | |
var boxs = document.querySelectorAll('.all_check_boxs'), | |
form = document.querySelector("#the_form"); | |
check_box(boxs); | |
function check_box(boxs) { | |
var id_array = []; | |
for (var cont = 0; cont < boxs.length; cont++) { | |
boxs[cont].onclick = function() { | |
/*Se selecionado, coloca o valor dele no array*/ | |
if (this.checked == true) { | |
id_array.push(this.value); | |
} | |
/*Se desmarcado, retira o valor dele do array*/ | |
if (this.checked == false) { | |
id_array.shift(this.value); | |
} | |
/*Verifica se dois checkbox foram selecionados*/ | |
if (id_array.length == 2) { | |
form.submit(); | |
} | |
} | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment