I have the code below that generates rooms in my selects.
str += '<select class="select-group" id="selQuartos">';
str += '<option>Qtd. quartos</option>';
for (var i = 1; i < $("#Quartos").val() + 1; i++) {
if (i == 1) str += '<option>' + i + ' quarto</option>';
else str += '<option>' + i + ' quartos</option>';
if (i == $("#Quartos").val()) break;
}
str += '</select>';
I have this javascript function that validates whether there are checkboxes checked or not. I would add in this validation if there are rooms selected in my combos above, but I can not do it. Checkboxes get the values checked and you're done. Now how to do with Combos? I tried this way: if($("selQuartos").val() < 1)
... This did not work, because I can not bring the value of the Selector (Combobox). Below javascript to validate:
function Submit() {
var Apartmento = [];
var retorno = false;
for (var i = 0; i < filtroPesquisa.chkApartmento.length; i++) {
if (filtroPesquisa.chkApartmento[i].checked) {
Apartmento.push(filtroPesquisa.chkApartmento[i].value);
}
}
if (Apartmento.length == 0) {
for (var i = 0; i < filtroPesquisa.chkApartmento.length; i++) {
filtroPesquisa.chkApartmento[i].style.color = "red";;
}
retorno = false;
} else {
retorno = true;
}
So, I started doing what FS.DEV posted. If I comment the for and give false return, it does not go to another page, but if I leave the for even with return false, it goes to another page. As it calls another page, I can not catch it if there is or not javascript error. Here's how I'm doing. I put the return false just for testing.
function Submit() {
var _selSeguro = document.getElementById('selSeguro');
var _selIngresso = document.getElementById('selIngresso');
var _selPasseio = document.getElementById('selPasseio');
var selecionados = new Array();
for(var i = 0; i <_selIngresso.length; i++)
if(_selIngresso[i].selected)
selecionados.push({'id':i,'valor':_selIngresso.value});
return false;
}
I noticed something important here. When the page comes in, comes the sliders closed. When I open a slider, it shows me the buttons and combos to fill. With the sliders open, the button to navigate the other page obeys the return of the function. This only does not happen when the sliders are closed. Does anyone know why?
I made that form and it did not work.
if ((_selIngresso.value == '') && (_selPasseio.value == '') && (_selSeguro.value == ''))
return false;
If I do one by one, it works, but they all do not, because when I open a slider, the denials close and this validation only happens when the sliders are open. Anyone have any ideas how to do this?
I said slider, but now I see that ACCORDION is called the effects, ie when one opens the other closes. When it's closed, I can not take anything from it, nothing at all. Then it gives javascript error and the button calls the page.