Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conditional operators in javaScript

 
Anant Rao
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do realize that that code is doing string comparisons?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that helped me out.


Infyniti
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic