external javascript file won't work -...

User 3382 Photo


Registered User
1 post

This is all being done in the HTML Editor V2008.

I put my mouseover javascript in a .js file and call that from the html heading. It doesn't work... When I put the javascript code in the heading it works fine. Here is how I am calling the .js file:

<script src="StyleSheet1.js"
language="javascript"
type="text/javascript">
</script>

The above code is in the heading...

Here is the StyleSheet1.js file:

if (document.images) {
img1_on =new Image(); img1_on.src ="gray_back_on.gif";
img1_off=new Image(); img1_off.src="gray_back.gif";

img2_on =new Image(); img2_on.src ="gray_home_on.gif";
img2_off=new Image(); img2_off.src="gray_home.gif";

img3_on =new Image(); img3_on.src ="gray_next_on.gif";
img3_off=new Image(); img3_off.src="gray_next.gif";

// Function to 'activate' images.
function movr(k) {
if (document.images)
eval('document.img'+k+'.src=img'+k+'_on.src');
}

function mout(k) {
if (document.images)
eval('document.img'+k+'.src=img'+k+'_off.src');
}

function handleOver() {
if (document.images) document.imgName.src=img_on.src;
}

function handleOut() {
if (document.images) document.imgName.src=img_off.src;
}
}

Will somebody 'hep' me?????? What am I doing wrong? I am pulling out my hair trying to solve this and at my age, I can't afford that....
User 119331 Photo


Registered User
3 posts

Is stylesheet1.js located in the root folder? The same place as your html file?

.. and are your images in the root as well or in an images folder?

Try using CSS for rollovers ... far easier.
- Dania
User 78330 Photo


Registered User
198 posts

Try
<script type="text/javascript" src="stylesheet1.js"></script>


Your problem may be caused by either the statement being the wrong way round and also the use of upper case.

Always write code in lower case. It makes it much easier in avoiding mistakes because some servers don't like case mixing.

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.