By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,914 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

javascript null..is it a string?

P: 7
hi, i'm wondering why is it javascript doesn't seem to accept null value as a real null? In order to know if its a null field later on, it's as if i have to check it against a string 'null'.

for example,
i have a txtName hidden field on my html.

I use javascript to

Expand|Select|Wrap|Line Numbers
  1. document.myForm.txtName.value = null;
later on, when i try to detect it just doesn't work :

Expand|Select|Wrap|Line Numbers
  1. if(document.myForm.txtName.value == null){
  2.  alert('value is null');
  3. }else if(document.myForm.txtName.value == 'null'){
  4.  alert('value is a string null'); //only this works!
  5. }
Nov 24 '07 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,390
hi ...

ALL values that you retrieve from a page/field are handled as strings ... since the value is considered as the nodeValue of a textnode ...

kind regards
Nov 24 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.