459,466 Members | 1,128 Online
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

# Comparison Operators

 100+ P: 150 I'm having problem with this code: Expand|Select|Wrap|Line Numbers function check(){     element1 = 2;     element2= 110;     if(element1 > element2){         alert('Sorry, element1 should be less than element2');     } } what is the problem in this code ??? Jan 2 '09 #1
5 Replies

 Expert Mod 5K+ P: 5,390 ?? where is the problem ?? ... 2 isn't greater then 110 so you don't get the alert ... Jan 2 '09 #2

 100+ P: 150 i know that 2 isn't greater than 110 but i get the alert message how can i solve this problem I'm getting mad that is my real code: Expand|Select|Wrap|Line Numbers function is_numeric(mixed_var){     return !isNaN(mixed_var); } if(is_numeric(value) && is_numeric(compv)){     if(condi == '<' && (compv < value)){         forError(this.elemID,'Sorry, '+elemID+' should be less than '+compn);     }else if(condi == '>' && (compv > value)){         forError(this.elemID,'Sorry, '+elemID+' should be greater than '+compn);     }else if(condi == '>=' && (compv >= value)){         forError(this.elemID,'Sorry, '+elemID+' should be greater than or equal '+compn);     }else if(condi == '<=' && (compv <= value)){         forError(this.elemID,'Sorry, '+elemID+' should be less than or equal '+compn);     } }else{     forError(this.elemID,'Sorry, numeric letters only'); } Jan 2 '09 #3

 Expert Mod 5K+ P: 5,390 so you just posted the wrong code ... but i think your problem is that you in fact compare strings like that: Expand|Select|Wrap|Line Numbers element1 = '2'; element2 = '110';   if (element1 > element2) {     alert('Sorry, element1 should be less than element2'); }   so you just need to parseInt() or parseFloat() the values. kind regards Jan 2 '09 #4

 100+ P: 150 thank you for your replay gits that was my problem. Jan 2 '09 #5

 Expert Mod 5K+ P: 5,390 no problem ... you're welcome ... kind regards Jan 2 '09 #6