Skip to content

Instantly share code, notes, and snippets.

@valdiney
Created March 26, 2016 23:27
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/79972677fa1008ff0daf to your computer and use it in GitHub Desktop.
Save valdiney/79972677fa1008ff0daf to your computer and use it in GitHub Desktop.
$(document).ready(function() {
window.onload = function() {
var boxs = document.querySelectorAll(".all_check_boxs"),
form = document.querySelector("#the_form"),
button_comparar = document.querySelector("#sim_comparar"),
button_cancelar = document.querySelector("#cancelar_comparacao"),
id_array = [];
check_box(boxs);
function check_box(boxs) {
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) {
$("#modal_comparar").modal({show:true});
button_comparar.onclick = function() {
form.submit();
return false;
}
}
}
}
} // end function
/*Retira todos os Valores contidos no Vetor*/
button_cancelar.onclick = function() {
id_array.length = 0;
for (var cont = 0; cont < boxs.length; cont++) {
boxs[cont].checked = false;
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment