SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    London
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rollover script problems

    I'm using a rollover script in two pages but whilst it will work fine in one page, it refuses to in the other. I've been through it but can't find where the problem lies - as far as I can see, they're identical. I'd appreciate it someone else could have a look through and find anything - it's driving me mad

    The script that's behaving
    <SCRIPT language="javascript">
    browserName=navigator.appName;
    browserVer=parseInt ( navigator.appVersion);

    version="n2";
    if (browserName == "Netscape" && browserVer >=4) version = "n4"
    if (browserName == "Microsoft Internet Explorer" && browserVer >=4) version="e4"

    if (version == "n4" || version == "e4")
    {

    square1_on=new Image ( 69, 19 );
    square1_on.src="images/square1_on.gif";
    square2_on=new Image ( 69, 19 );
    square2_on.src="images/square2_on.gif";
    square3_on=new Image ( 69, 19 );
    square3_on.src="images/square3_on.gif";

    square1_off=new Image ( 69,19 );
    square1_off.src="images/square1_off.gif";
    square2_off=new Image ( 69,19 );
    square2_off.src="images/square2_off.gif";
    square3_off=new Image ( 69, 19 );
    square3_off.src="images/square3_off.gif";
    }
    function button_on ( imgName )
    {
    if (version == "n4" || version == "e4")
    {
    butOn = eval ( imgName + "_on.src");
    document[imgName].src = butOn;
    }
    }
    function button_off ( imgName)
    {
    if (version == "n4" || version == "e4")
    {
    butOff = eval ( imgName + "_off.src");
    document[imgName].src = butOff;
    }
    }
    </SCRIPT>

    And the script that isn't:
    browserName=navigator.appName;
    browserVer=parseInt (navigator.appVersion);

    version = "n2"
    if (browserName == "Netscape" && browserVer >=4 ) version = "n4"
    if (browserName == "Microsoft Internet Explorer" && browserVer >=4 ) version="e4"

    if (version == "n4" || version == "e4" )
    {

    square1_on=new Image ( 69, 19 );
    square1_on.src="images/square1_on.gif";
    square2_on=new Image ( 69, 19 );
    square2_on.src="images/square2_on.gif";
    square3_on=new Image ( 69, 19);
    square3_on.src="images/square3_on.gif";

    square1_off=new Image ( 69, 19 );
    square1_off.src="images/square1_off.gif";
    square2_off=new Image ( 69, 19 );
    square2_off.src="images/square2_off.gif";
    square3_off=new Image ( 69, 19);
    square3_off.src="images/square3_off.gif";
    }
    function button_on ( imgName )
    {
    if (version == "n4" || version == "e4")
    {
    butOn = eval ( imgName + "_on.src");
    document[imgName].src = butOn;
    }
    }
    function button_off ( imgName)
    {
    if (version == "n4" || version == "e4")
    {
    butOff = eval ( imgName + "_off.src");
    document[imgName].src=butOff;
    }
    }
    </SCRIPT>

    When I preview the non-working one, it tells me that both of the document[imgName] are null or not objects.

    Please save my sanity!!
    Jo

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OUCH @ declaration methods.

    Why not have the names in an array, loop the array an create
    the Images through that?

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    London
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would I do that?

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think i pointed this out recently for someone else:

    Code:
    var imgs = new Array('nav_home','nav_gallery');
    
    for (var i=0;i<imgs.length;i++){
          eval('var '+imgs[i]+' = new Image()');
          eval(imgs[i]+'.src = "'+imgs[i]+'.gif"');
          eval('var '+imgs[i]+'_o = new Image()');
          eval(imgs[i]+'_o.src = "'+imgs[i]+'_o.gif"');
          }
    
    function handle(event){
          var s = event.srcElement || event.currentTarget || event.target;
          s.src = eval(s.name+((event.type.match('over'))?'_o':'')+'.src');
          }
    There's a link for an example too i think - i'll look around
    for it for you...

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes - it was for Defender1, so:

    http://www.passway.org/defender.html

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    London
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks very much - I'll give that a try. I'd still like to know what's up though, just to set my poor strained brain to rest!!

    Jo

  7. #7
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i never got further than the first six lines
    before deciding to point you in a better direction - so
    i'm afraid i wouldn't know

    If it gets FAR too much for you - i'll take a look at it
    later - but for now you can just let it trouble your mind

    he he

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


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
  •