setting form values via external js file ... trying to use document.form.filed.value

J

jason

I have a function that <body onload=..> sets some form values. However
when i execute that functionf from external js file, i get erorrs and
it dont work.

The function sets the fields via

document.forname.fieldname.value = xx;

I would imagine document no longer applies since external js file. How
can i do this from an external js file.

thanks.
 
M

Michael Winter

[snip]
document.forname.fieldname.value = xx;

I would imagine document no longer applies since external js file.

Not at all. The script will act exactly as it would had you pasted the
contents within a SCRIPT element.
How can i do this from an external js file.

As you normally might.

Could you show an example, preferably presenting a small demonstration
somewhere on the Web.

Mike
 
J

jason

Thanks for response.

I found my bug. I had left the <script language> tag in the .js file
.... and apparently you can't have html in an external js file so the
function was not being found.

Incidently, what's the best way to expand on these javascript errors
you might get at the bottom of the browser screen. Any way to get more
detail, and maybe a line number or something. I'm using IE 6.0.

Thanks.
 
M

Michael Winter

Thanks for response.

You're welcome.
I found my bug. I had left the <script language> tag [...]

The language attribute is deprecated, by the way. It has been for over six
years. The script type should be specified using the type attribute:

... and apparently you can't have html in an external js file so the
function was not being found.

No, you certainly can't. The external file should only contain content
that is valid for the script language.
Incidently, what's the best way to expand on these javascript errors you
might get at the bottom of the browser screen. Any way to get more
detail, and maybe a line number or something. I'm using IE 6.0.

You can add the Microsoft Script Debugger, but I found it cumbersome to
use. I would recommend using another browser, which is generally a good
idea for Web development anyway as you don't fall into the trap of using
Microsoft-only "features"[1].

Opera's Javascript console automatically includes a trace through your
script that's very useful in determining what went wrong, where. The
development tools that come with the Mozilla Browser Suite and Mozilla
Firefox are also better than the IE console.

Opera <URL:http://www.opera.com/>
Mozilla <URL:http://www.mozilla.org/>

Mike


[1] Unless you're developing for a Microsoft-only environment, of course.
 

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,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top