![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
SCRIPT LANGUAGE="javascript" var m = (document.getElementById && document.getElementById('moreText')) ? document.getElementById('moreText').value : '<PRE>no more text</PRE>'; document.writeln(m); /SCRIPT |
#3
| |||
| |||
|
|
Hi All, The following code works in IE but not Firefox. IE produces the expected "this is more text!" output, but Firefox produces "no more text". Any ideas why? BODY FORM INPUT TYPE=HIDDEN NAME="moreText" VALUE="<PRE>This is more text!</PRE>" SCRIPT LANGUAGE="javascript" var m = (document.getElementById && document.getElementById('moreText')) ? document.getElementById('moreText').value : '<PRE>no more text</PRE>'; document.writeln(m); /SCRIPT /FORM /BODY FYI, I've tried it with the script both within and outside the form, and the code behaves identically. Thanks! -Dave H. |
#4
| |||
| |||
|
|
The following code works in IE but not Firefox. [...] INPUT [...] NAME="moreText" [...] ~~~~ [...] document.getElementById('moreText') ~~~~ [...] |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
You cannot do a document.write() when the page is already loaded and on screen without destroying the whole page, including the javascript. |
#7
| |||
| |||
|
|
You cannot do a document.write() when the page is already loaded and on screen without destroying the whole page, including the javascript. |
#8
| |||
| |||
|
|
You cannot do a document.write() when the page is already loaded and on screen without destroying the whole page, including the javascript. This is a true statement, but it doesn't apply to the original poster becuase the page hasn't been loaded since the </body> hasn't been encountered. I added the id tag to make it work in more browsers. BODY FORM INPUT TYPE=HIDDEN NAME="moreText" id="moreText" VALUE="<PRE>This is more text!</PRE>" SCRIPT LANGUAGE="javascript" var m = (document.getElementById && document.getElementById('moreText')) ? document.getElementById('moreText').value : '<PRE>no more text</PRE>'; document.writeln(m); /SCRIPT /FORM /BODY |
#9
| |||
| |||
|
|
Robert wrote: You cannot do a document.write() when the page is already loaded and on screen without destroying the whole page, including the javascript. This is a true statement, but it doesn't apply to the original poster becuase the page hasn't been loaded since the </body> hasn't been encountered. I added the id tag to make it work in more browsers. BODY FORM INPUT TYPE=HIDDEN NAME="moreText" id="moreText" VALUE="<PRE>This is more text!</PRE>" SCRIPT LANGUAGE="javascript" var m = (document.getElementById && document.getElementById('moreText')) ? document.getElementById('moreText').value : '<PRE>no more text</PRE>'; document.writeln(m); /SCRIPT /FORM /BODY You could make it work in even more browsers if you used the forms collection and referenced the form element by its name attribute. If for no other reason that there are more browsers that support the forms collection than browsers that support document.getElementById var m = (document.forms && document.forms['moreText'] && document.forms['moreText'].value) ? document.forms['moreText'].value : '<pre>No More Text</pre>'; document.write(m) |
#10
| |||
| |||
|
|
In MSIE only, name and id attributes share one namespace. Simply add an id="moreText" attribute to the input element. |
![]() |
| Thread Tools | |
| Display Modes | |
| |