By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
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
  1. function check(){
  2.     element1 = 2;
  3.     element2= 110;
  4.     if(element1 > element2){
  5.         alert('Sorry, element1 should be less than element2');
  6.     }
  7. }
what is the problem in this code ???
Jan 2 '09 #1
Share this Question
Share on Google+
5 Replies


gits
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
  1. function is_numeric(mixed_var){
  2.     return !isNaN(mixed_var);
  3. }
  4. if(is_numeric(value) && is_numeric(compv)){
  5.     if(condi == '<' && (compv < value)){
  6.         forError(this.elemID,'Sorry, '+elemID+' should be less than '+compn);
  7.     }else if(condi == '>' && (compv > value)){
  8.         forError(this.elemID,'Sorry, '+elemID+' should be greater than '+compn);
  9.     }else if(condi == '>=' && (compv >= value)){
  10.         forError(this.elemID,'Sorry, '+elemID+' should be greater than or equal '+compn);
  11.     }else if(condi == '<=' && (compv <= value)){
  12.         forError(this.elemID,'Sorry, '+elemID+' should be less than or equal '+compn);
  13.     }
  14. }else{
  15.     forError(this.elemID,'Sorry, numeric letters only');
  16. }
Jan 2 '09 #3

gits
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
  1. element1 = '2';
  2. element2 = '110';
  3.  
  4. if (element1 > element2) {
  5.     alert('Sorry, element1 should be less than element2');
  6. }
  7.  
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

gits
Expert Mod 5K+
P: 5,390
no problem ... you're welcome ...

kind regards
Jan 2 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.