Why does the size of a text input grow when using JS to create a page?

S

Scott Navarre

Hello,

I have noticed that when using JavaScript to create a page, the sizes of
the text input form elements come out bigger than the size I am trying to
set them to. I don't know if it matters, but I am using IE6...

For example: if I create a text input with a size of "1" using straight
HTML, and then type into it, I can see 2 characters at a time. But when I
use JavaScript's 'document.write()' function to create the same text input,
it is noticeably bigger and when I type into it I can see 5 characters at a
time.
Here is a short, simple example to illustrate the problem:

<HTML>
<HEAD>
<TITLE>JavaScript Test</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function createPage()
{
var page='';
page+='<HTML>';
page+='<TITLE>JavaScript Test</TITLE>';
page+='<BODY>';
page+='<FORM>';
page+='Text Input (Size="1"): <INPUT TYPE="TEXT" SIZE="1">';
page+='</FORM>';
page+='</BODY>';
page+='</HTML>';
document.write(page);
document.close();
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
Text Input (Size="1"): <INPUT TYPE="TEXT" SIZE="1">
<BR><BR><BR>
<INPUT TYPE="BUTTON" VALUE="Re-render this page using JavaScript"
onClick="createPage()">
</FORM>
</BODY>
</HTML>

Am I missing something (doing something wrong)? Or is there anything that
can be done to fix this problem?

Thanks in advance,
Scott Navarre
 

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
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top