how to use javascript write text to an Input text box

A

acord

Hi,

I tried to assign some string to document.my_form.firstname.value, but
the text box does not display anything.
eg.
document.my_form.firstname.value = "Robert"

in this example, the text box area does not display Robert in the web page.

Thanks
A
 
E

Evertjan.

acord wrote on 24 mrt 2006 in comp.lang.javascript:
I tried to assign some string to document.my_form.firstname.value, but
the text box does not display anything.
eg.
document.my_form.firstname.value = "Robert"

in this example, the text box area does not display Robert in the web
page.

Use:

document.forms['my_form'].elements['firstname'].value = "Robert"

Your problem could be that the form is not ready, as the above only works
when the form has been set up in the DOM.
 
T

Tim Streater

Evertjan. said:
acord wrote on 24 mrt 2006 in comp.lang.javascript:
I tried to assign some string to document.my_form.firstname.value, but
the text box does not display anything.
eg.
document.my_form.firstname.value = "Robert"

in this example, the text box area does not display Robert in the web
page.

Use:

document.forms['my_form'].elements['firstname'].value = "Robert"

Your problem could be that the form is not ready, as the above only works
when the form has been set up in the DOM.

So do it in the onload.

-- tim
 
E

Evertjan.

Tim Streater wrote on 24 mrt 2006 in comp.lang.javascript:
Evertjan. said:
acord wrote on 24 mrt 2006 in comp.lang.javascript:
I tried to assign some string to document.my_form.firstname.value,
but the text box does not display anything.
eg.
document.my_form.firstname.value = "Robert"

in this example, the text box area does not display Robert in the
web page.

Use:

document.forms['my_form'].elements['firstname'].value = "Robert"

Your problem could be that the form is not ready, as the above only
works when the form has been set up in the DOM.

So do it in the onload.

That could be done, Tim,
but why not [then!] just write the text in the
<input value='.....'

Look, no hands, .... eh javascript.

The OP is not clear over his intentions.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top