Jump to content

Javascript simple if check


harshpandya

Recommended Posts

Here is the code - why it wont work. alert(val1 + " and " + val2); //val1 and val2 are same if(val1 == val2){ dosomething(); }else{ dosomethingnew(); insRow('myTable', searchForBack+" "+svalueBack, 'failed', 'N/A'); }Note:::: here val1 is number (val1 = 20) and val2 is string (val2 = 20)val1 is just value i assigned to variable val2 is string that i parse from bigger string.so i believe i want to check is if(val1 == val2). and it does not work in above codePlease help,Thanks,

Link to comment
Share on other sites

Not working !!!First i check the type of these var1 and var2 ::::::They both are strings for sure:: if (typeof val1 == "string") { alert('val1 is string.') } if (typeof val1 == "number") { alert('val1 is number.') } if (typeof val2 == "string") { alert('val is string.') } if (typeof val2 == "number") { alert('val1 is number.') } parseInt(val1, 10); parseInt(val2, 10); if(val1 == val2){ alert("equal"); }Did not work.... i also tried val1===val2 for strings, Please Help --

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...