• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null in Javascript code

 
pramod talekar
Ranch Hand
Posts: 328
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Below is my code:




In the above code, when the field.value.length is 0 , the loop gets executed,
how come helpText is not null ?

Also
For the above loop, if I enter message in the field, the rest of the fields go off the screen.
The solution to this is that I need to change the above loop condition to
Why do I need to change this from != to == ?

Please advise.

 
joy b chakravarty
Ranch Hand
Posts: 62
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
validateNonEmpty(this,document.getElementById('message_help')


this means helptext = document.getElementById('message_help');
and as your form has
<span id="message_help" />

helpText would never be null..

in fact you could rewrite

as
 
pramod talekar
Ranch Hand
Posts: 328
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Joy,

So I assume that as helpText is referring to something (element "message_help") so it can't be null.

What I don't understand is that why I need to write "==" instead of "!=".
Actually the book I'm using does show "!=" but it doesn't work.

Also, as helpText is not null and so is my message field, then how come helpText becomes null or why is this condition getting executed ?



 
pramod talekar
Ranch Hand
Posts: 328
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joy,


validateNonEmpty(this,document.getElementById('message_help')


this means helptext = document.getElementById('message_help');
and as your form has
<span id="message_help" />

helpText would never be null..


Then why

is getting executed ?
 
joy b chakravarty
Ranch Hand
Posts: 62
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I'm not getting that alert ..please check
also i strongly recommend you to put the missing brackets else its very confusing

if()
alert(1);
if()
alert(2);
alert(3);
alert(4)

to be honest i don't know which all alerts will popup
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic