View Full Version : a NewBie "Duhhh" kinda question

Apr 11th, 2005, 04:37 PM
Hi Folks,

I want to use javascript to manage a single "Return to Index Page" kind of button.
I also want to use two different images for this button. A <onMouseOver> image as well as an <OnMouseOut> image.
The button is going to be placed on all the html pages in the directory, and will also probably be at several locations in each of the pages.
It occurs to me that I SHOULD put the javascript code in a single file... say "Return.js" but I don't know how. It makes sense, because I wouldn't have to rewrite the stuff all over the place.
So... that's really two questions:
How do I make such a "Return.js" file?
How do I refer to a 'function' in the ".js" file from an HTML page, and importantly... can I refer to it more than once and still retain the animation?

Many thanks,

Apr 11th, 2005, 04:55 PM
you should write the event handler and the function called anyway in all the pages, so probably, if you mean a single button, maybe it is easier to use

<img src="normalbut.gif" onmouseover="this.setAttribute('src','rolloverbut.gif')" onmouseout="this.setAttribute('src','normalbut.gif')">

Or you wanna know how to write a generic rollover code?

If you have a js code which is to be used in several pages, just put the code (without the <script type="text/JavaScript"> and </script> markers) in an external JS file, name it whichever (say myscript.js). Put this in the HEAD of each page.
<script type="text/javascript" src="myscript"></script>

Apr 11th, 2005, 05:24 PM
Thanks Kor...

I've followed your suggestion, and it works just as I had hoped it would...
as a matter of fact... even better than I had hoped.

Thanks again,

and by the way... Romania in the EU.. why not? How do I support such a thing, anyway?


Apr 12th, 2005, 08:08 AM
Romania in the EU.. why not? How do I support such a thing, anyway?

If you are a member in the European Parliament, vote for us on the 13th of April. Or lobby for us to a member of EU Parliament... :thumbsup: