• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

less than < not wokring in js when compare the value and defaultValue

 
Ganesan Ramakrishnan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an issue while check the following condition in java script,



less than < not wokring in js when compare the value and defaultValue?

Regards,
Ganesan
 
Rob Crowther
author
Ranch Hand
Posts: 297
5
Android Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have any element with an id of one, what are you expecting your calls to getElementById('one') to return?
 
Ganesan Ramakrishnan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have assigned default value as 10.
now i am changing value to 5.
then i clicks the button , it calls the function check().

5 < 10

then the if condition must be execute.
but it not so..



i suspecting the defaultValue return type.

Regards,
Ganesan
 
Matthew Brown
Bartender
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Rob said: there is no element with ID "one". document.getElementById('one') will return null. Therefore document.getElementById('one').value will be an error.

"name" and "id" are not the same attribute.
 
Ganesan Ramakrishnan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please assume i am having id in my text field tag.



still my problem is persist.

i want have below alert message when enter the 5, assume default valus is 10,


but am not getting tha above alert message
 
Rob Crowther
author
Ranch Hand
Posts: 297
5
Android Fedora Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you're comparing strings, and the string "10" is alphabetically before the string "5". Try:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic