SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    May 2000
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can someone please take a look at this script and maybe tell me whats going wrong?

    I THINK that its not in the functions because it loads without error but as soon as io place the mouse over it, i get an error notice in the browser status bar.

    heres the code:

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>

    &lt;html&gt;
    &lt;head&gt;
    &lt;title&gt;Untitled&lt;/title&gt;

    &lt;SCRIPT LANGUAGE="JavaScript"&gt;
    &lt;!-- Begin
    newsOn = new Image(36, 120);
    newsOn.src = "images/news_on.gif";
    newsOff = new Image(36, 120);
    newsOff.src = "images/news_off.gif";
    // End --&gt;
    &lt;/script&gt;
    &lt;/head&gt;
    &lt;script language="javascript"&gt;
    &lt;!--
    function imageOn(imgName) {
    if (browserOK == "yes") {
    imgOn = eval(imgName + "On.src");
    document[imgName].src = imgOn;
    }
    }

    function imageOff(imgName) {
    if (browserOK == "yes") {
    imgOff = eval(imgName + "Off.src");
    document[imgName].src = imgOff;
    }
    }
    --&gt;
    &lt;/script&gt;
    &lt;body&gt;
    &lt;a href="testimgover.htm" onMouseover = "imageOn('news')" onMouseout = "imageOn('news')"&gt;
    &lt;img name="news" src="images/news_off.gif" border="0"&gt;
    &lt;/a&gt;
    &lt;/body&gt;
    &lt;/html&gt;

    [/code]
    please help, ive been kicking this horse for hours... This is my first javascript installation and its not treating me kindly =(

    but i want a mousover script that works with as many browsers as possible

    Thank you so much


  2. #2
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    District of Columbia
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote/font><HR>Originally posted by jizbot:
    &lt;a href="testimgover.htm" onMouseover = "imageOn('news')" onMouseout = "imageOn('news')"&gt;
    &lt;img name="news" src="images/news_off.gif" border="0"&gt;
    &lt;/a&gt;
    [/B]<HR></BLOCKQUOTE>


    onMouseOut = "imageOff('news')"
    should do it

    and whats BrowserOK? Does the error you are getting look like this: 'BrowserOK' is undefined??

  3. #3
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    BrowserOK is most likely a flag that can be checked to see if the procedure will work.

    For Example:
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    BrowserOK ="No"
    if document.images {BrowserOk = "Yes"}
    [/code]

    This will tell the script if the browser is capable of scripting images.


    ------------------
    Wayne Luke - Sitepoint Forums Administrator
    Digital Magician Magazine - MetaQuark Creations (Coming Soon)
    wayne@sitepoint.com

  4. #4
    SitePoint Addict
    Join Date
    May 2000
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes browserOk is a variable that hold "yes" or "no" after a test is run to make sure the browser is either IE 3 or above or NE 4 or above i believe

    sorry i didnt realize i didnt post that too =(

  5. #5
    SitePoint Addict
    Join Date
    May 2000
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok heres the full code:

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    &lt;html&gt;
    &lt;head&gt;
    &lt;title&gt;Untitled&lt;/title&gt;
    &lt;/head&gt;

    &lt;SCRIPT LANGUAGE="JavaScript"&gt;
    &lt;!-- Begin
    browserName = navigator.appName;
    browserVer = parseInt(navigator.appVersion);
    if ((browserName == "Netscape" && browserVer &gt;= 3) &#0124; &#0124; (browserName == "Microsoft Internet Explorer" && browserVer &gt;=4)) {
    browserOK = "yes";
    else
    browserOK = "no";
    }

    if (browserOK == "yes")
    newsOn = new Image(36, 120);
    newsOn.src = "images/news_on.gif";
    newsOff = new Image(36, 120);
    newsOff.src = "images/news_off.gif";


    function imageOn(imgName) {
    if (browserOK == "yes") {
    imgOn = eval(imgName + "On.src");
    document[imgName].src = imgOn;
    }
    }

    function imageOff(imgName) {
    if (browserOK == "yes") {
    imgOff = eval(imgName + "Off.src");
    document[imgName].src = imgOff;
    }
    }
    --&gt;
    &lt;/script&gt;

    &lt;body&gt;
    &lt;a href="testimgover.htm" onMouseover = "imageOn('news')" onMouseout = "imageOff('news')"&gt;
    &lt;img name="news" src="images/news_off.gif" border="0"&gt;
    &lt;/a&gt;
    &lt;/body&gt;
    &lt;/html&gt;

    [/code]

  6. #6
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,263
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Shouldn't this one section of code look like this??
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
    if ((browserName == "Netscape" && browserVer &gt;= 3) | | (browserName == "Microsoft Internet Explorer" && browserVer &gt;=4)) {
    browserOK = "yes";
    }
    else
    {
    browserOK = "no";
    }

    if (browserOK == "yes") {
    newsOn = new Image(36, 120);
    newsOn.src = "images/news_on.gif";
    newsOff = new Image(36, 120);
    newsOff.src = "images/news_off.gif";
    }
    [/code]

    I added a closing bracket around the if browserOK == "yes" statement and added some more brackets to the code before it...

    I don't know a whole lot about javascript, but it would make sense for it to be coded like this.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •