Skip to content

Instantly share code, notes, and snippets.

@valdiney
Last active December 20, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valdiney/c5764a525d842bffa90c to your computer and use it in GitHub Desktop.
Save valdiney/c5764a525d842bffa90c to your computer and use it in GitHub Desktop.
Submete um formulário assim que dois checkboxs sejam selecionados
<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