473,508 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comparison Operators

150 New Member
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
5 1365
gits
5,390 Recognized Expert Moderator Expert
?? where is the problem ?? ... 2 isn't greater then 110 so you don't get the alert ...
Jan 2 '09 #2
smartic
150 New Member
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
5,390 Recognized Expert Moderator Expert
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
smartic
150 New Member
thank you for your replay gits that was my problem.
Jan 2 '09 #5
gits
5,390 Recognized Expert Moderator Expert
no problem ... you're welcome ...

kind regards
Jan 2 '09 #6

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

Similar topics

4
5388
by: Michael Klatt | last post by:
I've just encountered a strange situation (at least to me) regarding friend operators and member operators: #include <map> class Key { friend bool operator<(const Key& lhs, const Key& rhs)...
13
4579
by: jstanforth | last post by:
This is probably a very obvious question, but I'm not clear on what operators need to be implemented for std::map.find() to work. For example, I have a class MyString that wraps std::string, and...
29
2592
by: Steven D'Aprano | last post by:
Playing around with comparisons of functions (don't ask), I discovered an interesting bit of unintuitive behaviour: >>> (lambda y: y) < (lambda y: y) False Do the comparison again and things...
2
2036
by: PengYu.UT | last post by:
I'm wonder whether 1. stl directly defined the 6 comparison operators(== != < > <= >=) directly for iterator and const_iterator 2. or it only define == and < and using std::rel_ops to get the...
1
5087
by: Thats Me | last post by:
TMALSS: Task With maintenance of Access Database I did not develop, don't ask about non-commented code problems or where data dictionary is (LOL). Have table with Inventory data for all...
2
2592
by: Serve La | last post by:
Now that implementations are becoming available, I've started to learn more about C99. Now I was reading about the isgreater/isgreaterequal/isless/... macro's and I'm wondering about why they are...
37
2761
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
17
2013
by: Dinsdale | last post by:
I would like to compare a string value to a pre-determined list of other strings. Is there a simple way to do this in one statements like this: if(strMystring.ToUpper() == ("STRING1"| "STRING2"|...
2
2733
by: Mark Rae | last post by:
Hi, This isn't *specifically* an ASP.NET question, so I've also posted it in the ADO.NET group - however, it's not too far off-topic... Imagine a SQL Server 2005 database with a table with an...
2
3009
by: puzzlecracker | last post by:
Unlike C++, in Csharp you're only allowed to compare a generic type T with null, if the method it's passed in not implementing IComparable<Tor , IEquatable<T(still don't know why we need these...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.