JavaScript: The Definitive Guide

Previous Appendix D
JavaScript Incompatibilities in Internet Explorer 3.0
Next
 

D.3 Form Values and String Conversion

The JavaScript interpreter in Internet Explorer 3.0 does not always convert objects to strings when they are used in a "string context". This happens most notably when objects are assigned to the value field of form elements. To make this work correctly, you have to explicitly convert the object to a string, either by invoking its toString() method or by adding the empty string to it. To display the date and time in a form, for example, you'd have to use code like this:

today = new Date();
document.forms[0].dateandtime.value = today.toString()
or like this:

today = new Date();
document.forms[0].dateandtime.value = today + "";

If you encounter this conversion problem in other contexts, the workaround is the same.


Previous Home Next
Case Sensitivity Book Index Object Model Differences

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell