File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Conditional operators in javaScript

Anant Rao
Ranch Hand

Joined: Nov 12, 2004
Posts: 126

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 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
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63838

You do realize that that code is doing string comparisons?

[Asking smart questions] [About Bear] [Books by Bear]
Eric Pascarello

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

Anant Rao
Ranch Hand

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

I agree. Here's the link:
subject: Conditional operators in javaScript
It's not a secret anymore!