Solved

SCRIPT LANGUAGE  vs SCRIPT

Posted on 1997-05-08
8
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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
 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Bootstrap Form 16 41
How to get CSS styled menu to maintain the open selected menu? 13 45
arrays and radio buttons 10 40
AngularJS: ng-repeat 25 26
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

733 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