Posted on 1997-05-08
Medium Priority
Last Modified: 2012-05-04
I wrote a Javascript page kinda funky and mostly by the seat of my pants,, after hours it works fine on mouseovers in NN3, and not in IE, which I understand is normal..  
My problem... If I begin the script thusly
<SCRIPT LANGUAGE="JavaScript"> it won't work..
if I load it
<SCRIPT="JavaScript"> it loads and works..
it is at
Be happy to send the .txt file of the left pane mouseovers for some technical feller to troubleshoot for me and give me aid and comfort..
Question by:paulh@cybertrails.com
  • 4
  • 3

Expert Comment

ID: 1265461

I looked at your web site and it works very well. Since it is working, what exactly do you want an expert for?

Accepted Solution

jshamlin earned 200 total points
ID: 1265462
<SCRIPT="JavaScript"> is a syntax error.  Because of that, the tag is being ignored - it's kind of like a double negative - making an error that causes another error to be ignored results in something that works ... if the browser handles errors in a certain way.

The correct Syntax <SCRIPT LANGUAGE="javascript"> doesn't work because it causes the tags in between (all those <A HREF>s) to be read as script rather than HTML.  <SCRIPT> tags need to be used only with actual script (not even handlers embedded inside HTML).  For example ...

     <SCRIPT LANGUAGE="javascript">
     function myFunc(){

Is correct syntax - but if an HTML tag is included, it causes an error, because HTML tags aren't part of the Javascript language.

If a onMouseover tag is included in an HREF, you don't need <SCRIPT> tags.  onMouseover can only be Javascript, doesn't need <SCRIPT> tags, and is ignored by other browsers anyway.

So to clean things up ...

1. Get rid of the <SCRIPT> tags.
2. Close the <HEAD> tag before the <BODY> tag
3. replace <HTTP> and </HTTP> with <HTML> and </HTML>

... and everything will bne both functional and Kosher.


Author Comment

ID: 1265463
My face is RED for having put the <http> tags.. I'm new, and need some seasoning..
If you have a minute, could you write me a simple JavaScript page for a mouseover.. Using 1.gif as original image and 2.gif as the replace on mouseover. From that, I could, perhaps proceed to learn the correct sintax..
To make sure I understand, the mouseover I use without <SCRIPT> tags is simply an HTML function??
Thanks for your help..PAUL
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1265464
A follow up question.. even with the <SCRIPT> tags removed from my page I still get the error from IE when loading..
The page works fine afterward.. Is the error window normal??

Expert Comment

ID: 1265465
Don't worry too much 'bout the error - everyone has their moments (I spent half an hour trying to un-hose a page because I'd used &quot; instead of a real quotation mark inside the BODY tag <g>).

For clarification:

If a javascript command is embedded inside an HTML tag (such as onClick="statement;"), then you don't need the <SCRIPT> tag - only for free-standing script.

On the follow-up ...
Completely normal, and completely unavoidable.

You get errors in IE because IE doesn't understand the images[] array, so mouseOver image "switches" can't be done for IE at all.

To avoid the errors, you need to put in an "if" that tests for Netscape.  I have a pretty snappy mouseOver function that you're free to use.  IE still won't do the image switching, but it won't return errors, either.

Put this in the document <HEAD> (note that the <SCRIPT> tag is used because it's free-standing script)

<SCRIPT LANGUAGE="javascript">
     function switchout (position,filename){
             if((navigator.appName == "Netscape") && (navigator.appVersion.substring(0,1) > 2)){
             document.images[position].src='gifs/' + filename + '.gif'

You may need to alter the location of the .src unless your art is stored in a "gifs" folder on the same level as the page.

Then, for each image, do this (no <SCRIPT> tags) ...

<A HREF="document.html"
     <IMG SRC="gifs/is.gif" BORDER="0"></A>

The two values passed (0,is) are for the position of the image and the name of the GIF to "switch" the present one with.  In this example, onMouseover places gifs/isi.gif over images[0]; onMouseout re-places gifs/is.gif (the original image when the page was loaded) over images[0]


Author Comment

ID: 1265466
I'm so new to the JavaScript, that I guess it's not getting through.. I'm quite comfortable with html, but not getting through on Java..Could you do this for me...
the above script, could you write it "exactly" as I need to put it on a page, including the exact script for the browser check, if I have my html page and my .gif files stored in a common folder, and my .gif file is named
gif1.gif  and on mouseover it is to be replaced by  gif2.gif

I know I'm a bother, but if I can get one exact script and study it, I hope to get up and running... Thanks for all of your help, and your suggestions worked exactly as you indicated..

Expert Comment

ID: 1265467
No problem ... if I'm reding you right, all .html and .gif are in the same folder.  That'll take some adjustments - I'll also make a minor change to account for the fact that I don't know where the image will appear in the page ...

inside the <HEAD> tags, add this ...

<SCRIPT LANGUAGE="javascript">
<!-- hide
function switchout (position,filename){
    if((navigator.appName == "Netscape") &&
    (navigator.appVersion.substring(0,1) > 2)){
    document.bob.src=+ filename + '.gif'
// unhide -->

In the <BODY> where you want the image to appear, add these tags ...

<A HREF="document.html" onMouseover="switchout(0,'gif2')"
onMouseout="switchout(0,'gif1')"> <IMG SRC="gifs/gif1.gif" NAME="bob" BORDER="0"></A>

This will only work for the one image, though, because the function works with the image name ("bob") - the previous example used position in the images[] array, but ince I don't know what position the image is in, I gave it a name.

If you need to switch-out a second image, put NAME="fred" in the IMG tag and change the script line from "document.bob.src = [etc]" to document.fred.src = [etc])

Author Comment

ID: 1265468
Took out the + sign on the document.bob.src line and the application worked ..
Was unable to get a second pair of images to switch out using this example or the other one.. guess I'm just too thick to savvy.
When I use this script, does not the image return to '0', always place the same image on the return. So if I want to use several switchouts on same page.. as on my page, can it be done with this
example?? I named the gifs.. gif1, gif2, gif3, gif4, etc...
So if I want gif1 to appear on top, then on mouse over switch to gif2 and back on mouseout.. Then I want gif3 to appear on second position, and switchout to gif4 on mouseover and back on mouseout, etc. etc..
Wish I understood just what each line in the script was telling the browser..
I realize I'm a bother, but hoping to be able to understand this one function and then hoping to be able to branch out from there..
Have read quite a bit on JavaScript, but it's slow sinking in..
Thanks again..PAUL

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question