• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Null in Javascript code

 
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 62
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic