Setting form values with external .js file

D

dan_matthew

hi,
i'm trying to set a form value via an external js file. i don't know
javascript extremely well but i do know programming in general. anyway,
i thought this would be as easy as having a javascript file saved as
..js, and clicking it when i get to the page where i would like to set
the form value, with a code that looks like this -

document.form[0].myTextBox = "Search Term";

... if i click on this though, i get the error "document not defined."
can anyone help? as a concrete example, can someone show me the code
to, say, set the search textbox to the value "javascript" on
google/yahoo with said javascript file?

thank you thank you!

dan matthew
 
W

web.dev

dan_matthew said:
hi,
i'm trying to set a form value via an external js file. i don't know
javascript extremely well but i do know programming in general. anyway,
i thought this would be as easy as having a javascript file saved as
.js, and clicking it when i get to the page where i would like to set
the form value, with a code that looks like this -

document.form[0].myTextBox = "Search Term";

It's plural:

document.forms[0].myTextBox = "Search Term";
 
D

dan_matthew

Thank you for replying. I tried this, changing it to -

document.forms[0].myTextBox.value = "Search Term";

.... but I'm still getting the error message 'document' is undefined.

To add a little info in case it's relevant, what I do is I go to the
page where the text box is, then click on the javascript file which is
set as a favorite.

Any help will be much appreciated!
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top