By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,814 Members | 2,162 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,814 IT Pros & Developers. It's quick & easy.

Setting form values with external .js file

P: n/a
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

Sep 30 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

dan_matthew wrote:
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";
.. 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


Sep 30 '05 #2

P: n/a
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!

Sep 30 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.