Solved

SCRIPT LANGUAGE  vs SCRIPT

Posted on 1997-05-08
8
171 Views
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
http://www.geocities.com/CapitolHill/2844
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..
Thanks..
PAUL
0
Comment
Question by:paulh@cybertrails.com
  • 4
  • 3
8 Comments
 
LVL 5

Expert Comment

by:icd
ID: 1265461
Paul.

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

Accepted Solution

by:
jshamlin earned 100 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(){
        document.,images[9].src='thingy.gif';
     }
     </SCRIPT>

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.

0
 

Author Comment

by:paulh@cybertrails.com
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
0
 

Author Comment

by:paulh@cybertrails.com
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??
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 4

Expert Comment

by:jshamlin
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'
             }
     }
</SCRIPT>

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"
     onMouseover="switchout(0,'isi')"
     onMouseout="switchout(0,'is')">
     <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]


0
 

Author Comment

by:paulh@cybertrails.com
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..
Thanks..PAUL
0
 
LVL 4

Expert Comment

by:jshamlin
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 -->
</SCRIPT>

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])
0
 

Author Comment

by:paulh@cybertrails.com
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
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now