.change not firing the first time in ie7
Hi,
I am using:
- $(function() {
//----------------------------------------------onload
var viaje;
var total;
var precio;
var precio_opcion_total;
var num_viajeros = 0;
var opcion_precio;
var opcion_id;
calculate();
$("input:checkbox.checkbox_opciones").each(function(){
this.checked = false;
});
$("table.viaje").hide();
//----------------------------------------------events
$("select#viajes").change(function () {
$("select#viajes option:selected").each(function () {
viaje = ($(this).val()) ;
$("table.viaje").hide();
$("#viaje_"+viaje).show();
});
calculate ();
})
$("select#viajes").click(function() {
$(this).blur();
});
$("select#personas").change(function () {
$("select#personas option:selected").each(function () {
num_viajeros = ($(this).val()) ;
precio = $("table#viaje_"+viaje+" td.precio").text();
total = precio * num_viajeros;
$("td.num_viajeros").text(num_viajeros);
var pasajero = ""
for (i= 1; i < num_viajeros; i++) {
pasajero += "<label for='nombre_"+ (i+1) +"' id='nombre_"+ (i+1) +"_message'>"
pasajero += "Nombre y apellidos viajero "+ (i+1) +" *"
pasajero += "</label><br />"
pasajero += "<input name='nombre_"+ (i+1) +"' type='text' id='nombre_"+ (i+1) +"' size='50'><br />";
}
$("span#pasajero").html(pasajero);
});
$("input:checkbox.checkbox_opciones").change( function () {
opcion_id =$(this).val();
});
calculate ();
})
$("input:checkbox.checkbox_opciones").change( function () {
opcion_id =$(this).val();
if ($(this).parent("td").attr("class") == "no") {
$(this).parent("td").attr("class","yes")
} else {
$(this).parent("td").attr("class","no")
}
calculate ();
});
//-----------------------------------------------function
function calculate () {
var count = 1;
var gran_total = 0;
$("table#viaje_"+viaje+" tr.row:visible").each(function(){
var check_ok;
$(this).children().each(function() {
if (this.className == "yes") {
check_ok = "ok";
}
if (this.className == "no") {
check_ok = "ko";
}
if (this.className == "precio"){
if (check_ok == "ok") {
precio = $(this).text();
}
}
if (this.className == "num_viajeros"){
if (check_ok == "ok") {
viajeros = $(this).text();
}
}
if (this.className == "subtotal"){
if (check_ok == "ok") {
$(this).text(precio * num_viajeros);
gran_total += (precio * viajeros);
}
if (check_ok == "ko") {
$(this).text(0);
}
}
});
count++;
})
$("td.total").text(roundNumber(gran_total,2));
$("input#total").val(gran_total);
$("input#viaje_titulo").val($("select#viajes option:selected").text());
}
function roundNumber(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}
});
Basically, when the user selects a trip, or the number of travellers it triggers a table to show with the corresponding options, the problem I have is that in ie7, it doesn't trigger the first time, only the second time. I have seen a few posts saying they have a similar problem, but in their case, it triggers when they unfocus. I have tried using simple javascript to select one of the options manually, hoping it would count as a first change, and that then clicking the first time would do it, but nop.
the page is
http://www.flippa.es/paginas/es_compra1/compra_online.phpAny help would be really great, I really don't know what else to try...