473,569 Members | 2,352 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 1366
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
5392
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) { return lhs.myInt < rhs.myInt;
13
4590
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 which also implements ==, <, <=, >, >=, etc. (Those operators are tested and working correctly.) If I assign map = "world", it saves the...
29
2601
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 become even more bizarre: >>> (lambda y: y) < (lambda y: y) True
2
2053
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 other 4 operators. I made the following example for case 1. But I can not make it work. Could you please help me to make it work. Thanks,
1
5101
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 Publications held, contains binder number on shelf and is text data in numeric/alpha form i.e.; 123, 1234, 123a, 1234c. I want to stuff the last...
2
2596
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 here? What's the difference with the normal relational operators?
37
2774
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 behaviour, which is returning a value which is, really, id({}) < id(). He also said that default equality comparison will continue to be identity-based....
17
2019
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"| "STRINGX")) {} This syntax doesn't work (and in fact I'm not quite sure what this statement really is saying) but I'd like to be able to do...
2
2738
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 int column used for bitwise data - you know the sort of thing... 0, 1, 2, 4, 8, 16 etc intBitwise strName ----------------------
2
3017
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 two radically similar interfaces). In other words, Csharp enforces people to not make mistake, whereas C++ follows the philosophy "if you make a...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7982
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.