File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Conditional operators in javaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Conditional operators in javaScript" Watch "Conditional operators in javaScript" New topic
Author

Conditional operators in javaScript

Anant Rao
Ranch Hand

Joined: Nov 12, 2004
Posts: 126
Hi,

I am using struts and javascript for validation

I want to check two fiels with <= condition. When save button is clicked it should display a alert msg.

Below is the code:
if(document.form.TargetNumber.value <=document.form.SubmissionNumber.value){
alert("wrong number entered");
return false;
}

But the application behaves weird..at times it displays msg and yet times it does not. As per my oberservation if single digits are entered it works fine but when double digits are entered it does not throw the alert msg.

can any one help me out whats problem with code or suggest any alternative

Happy New Year
Infyniti.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

You do realize that that code is doing string comparisons?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
To add what Bear is saying you need to use parseInt or parseFloat on the values to make them numeric.

Eric
Anant Rao
Ranch Hand

Joined: Nov 12, 2004
Posts: 126
Thanks that helped me out.


Infyniti
 
 
subject: Conditional operators in javaScript