| Author |
Null in Javascript code
|
pramod talekar
Ranch Hand
Joined: Apr 26, 2010
Posts: 316
|
|
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.
|
Thanks,
Pramod
|
 |
joy b chakravarty
Ranch Hand
Joined: May 16, 2011
Posts: 62
|
|
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
|
Cheers, Joy [SCJP 1.4, SCBCD 5.0]
get high on alcohol, algorithm or both
|
 |
pramod talekar
Ranch Hand
Joined: Apr 26, 2010
Posts: 316
|
|
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
Joined: Apr 26, 2010
Posts: 316
|
|
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
Joined: May 16, 2011
Posts: 62
|
|
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
|
 |
 |
|
|
subject: Null in Javascript code
|
|
|