harshpandya Posted July 2, 2008 Share Posted July 2, 2008 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 More sharing options...
justsomeguy Posted July 2, 2008 Share Posted July 2, 2008 You can use parseInt to convert the string to an integer (or parseFloat).parseInt(val2, 10) Link to comment Share on other sites More sharing options...
harshpandya Posted July 2, 2008 Author Share Posted July 2, 2008 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 More sharing options...
justsomeguy Posted July 2, 2008 Share Posted July 2, 2008 You need to assign the return value of parseInt to something.val2 = parseInt(val2, 10) Link to comment Share on other sites More sharing options...
harshpandya Posted July 2, 2008 Author Share Posted July 2, 2008 Thanks worked fine - cool man Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.