Reputation: 36733
Here's my code:
$("#ddlCiudad").change(function () {
var idCity = $("#ddlCiudad").val();
$.getJSON("/ProductCheckout/GetPriceForLocation", { cityId: idCity, productId: idProduct, type: "land" },
function (cityData) {
console.log("Recieved json data.");
landCost = cityData.LandCost;
$("#billingshippingcost").text(landCost);
console.log("Assigned value of LandCost");
airCost = cityData.AirCost;
console.log("Assigned value of AirCost");
console.log(landCost); //Logs: 25,00
console.log(airCost); //Logs: "(an empty string)"
if (landCost == "") {
$(".land").removeClass("land").addClass("land-disabled");
}
else {
$(".land-disabled").removeClass("land-disabled").addClass("land");
}
if (airCost = "") {
$(".air").removeClass("air").addClass("air-disabled");
}
else {
$(".air-disabled").removeClass("air-disabled").addClass("air");
}
}
);
});
That if
statement is not being fired, any suggestions on why it's not firing?
Maybe an empty string
isn't the same as "" in Javascript.
Upvotes: 0
Views: 404
Reputation: 35793
Try:
if (!airCost) {
$(".air").removeClass("air").addClass("air-disabled");
}
else {
$(".air-disabled").removeClass("air-disabled").addClass("air");
}
Upvotes: 1