Mark
asked on
<body> onLoad function not working from javascript src
I have a function:
<head><script lang="javascript">
function doThis()
{
// do some things
}
</script></head>
In my html page I run this function onLoad:
<body onLoad="doThis();">
If I put this function in my <head><script> section right in the html page as shown,it works fine. If I try to put it in an external script file:
<head>
<script type="text/javascript" src="/myScripts/doThis.js" ></script>
</head>
It doesn't work and I get an 'object not found' message indicating the <body> line. What's up? Please note that I have other scripts in external files and they work fine, just not this one. Is a script not permitted to be external if called from the <body> tag?
<head><script lang="javascript">
function doThis()
{
// do some things
}
</script></head>
In my html page I run this function onLoad:
<body onLoad="doThis();">
If I put this function in my <head><script> section right in the html page as shown,it works fine. If I try to put it in an external script file:
<head>
<script type="text/javascript" src="/myScripts/doThis.js"
</head>
It doesn't work and I get an 'object not found' message indicating the <body> line. What's up? Please note that I have other scripts in external files and they work fine, just not this one. Is a script not permitted to be external if called from the <body> tag?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is the path to your js file? The path you are using would be in the myScripts folder directly off of the web root (C:\inetpub\wwwroot\myScri pts\doThis .js). Perhaps you meant it to be the myScripts folder under your web directory (C:\inetpub\wwwroot\yourap plication\ myScripts\ doThis.js) in which case your path should be:
<script type="text/javascript" src="/yourapplication/mySc ripts/doTh is.js" />
<script type="text/javascript" src="/yourapplication/mySc
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<script language="javascript" src="/myScripts/doThis.js"