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.

fiddle

looks me runs true branch regardless:

http://jsfiddle.net/tmwrv/

which makes sense. setting value 2, not checking value. statement $("#sendingtype").val(2) returns jquery object, "truthy".


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -