0

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.

4
  • 7
    Isn't that supposed to be if (airCost == "")? Commented Nov 4, 2011 at 13:52
  • @NullUserExceptionఠ_ఠ Yeah I fixed that already. :) The error still stands however. That condition is not passing. Commented Nov 4, 2011 at 13:53
  • 1
    Are you sure? Add something like console.log('airCost is empty') in the if block just to check if it gets there (and it's just the classes that aren't being added and removed correctly) Commented Nov 4, 2011 at 13:54
  • Btw, that edit doesn't apply. It completely changes my questions intent. Commented Nov 4, 2011 at 13:54

1 Answer 1

1

Try:

if (!airCost) {
    $(".air").removeClass("air").addClass("air-disabled");
}
else {
    $(".air-disabled").removeClass("air-disabled").addClass("air");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.