Javascript null

M

mj.redfox.mj

Hi,

Could anyone tell me why this...

document.forms[0].elements.value=null;

....appears to be assigning the actual string value of "null" to my form
element, rather than actually nullifying it?
 
V

VK

Hi,

Could anyone tell me why this...

document.forms[0].elements.value=null;

...appears to be assigning the actual string value of "null" to my form
element, rather than actually nullifying it?


Because all form element values are stored as strings and any value
will be converted to string before being assigned. And string
representation of null is "null".
To clear an element value set it to empty string:
document.forms[0].elements.value="";
 
M

mj.redfox.mj

Thanks, wasn't sure if that would definitely nullify it or not, but I
suppose it's just the same as leaving a field blank.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top