javascript - Strange jQuery behaviour -
i know $("#sendingtype").val(2)
sets value of select 2.
so, why goes else??
$(function () { $("#calculate").click(function () { var result = $("#sendingtype").val(); var day1 = eval(result) + 3; var day2 = eval(result) + 10; var day3 = eval(result) + 2; if ($("#sendingtype").val(2)) { $("#result").text(day1 + " , " + day2 + " days."); } else { $("#result").text(day1 + " , " + day3 + " days."); } }); });
i aware not correct way code if
statement.
solved: thank jason , juhana. code not go else, thought because value of select influences if result. if different results because of new select value.
looks me runs true
branch regardless:
which makes sense. setting value 2
, not checking value. statement $("#sendingtype").val(2)
returns jquery object, "truthy".
Comments
Post a Comment