Switch between images

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    #1

    Switch between images

    I´m trying to find out how to switch between an image by a mouseclick.

    The function should check if the image is on or off but it doesn´t work.
    What´s wrong?

    Below the script.

    start_on = new Image;
    start_on.src = "images/start_on.jpg";
    start_off = new Image;
    start_off.src = "images/start_off.jpg";

    function switch(image) {
    document.images[image].src = (document.image s[image].src.indexOf("_ off")==-1)? eval(image + "_off.src") ; eval(image + "_on.src")
    }

    <img border="0" name="start" src="images/start_on.jpg" onClick="switch ('start')">



    Thanks


    John


  • Janwillem Borleffs

    #2
    Re: Switch between images

    [color=blue]
    > "John" <jpeskensgeen@s pamhome.nl> schreef in bericht[/color]
    news:bo6ijf$dbh $1@news4.tilbu1 .nb.home.nl...[color=blue]
    > I´m trying to find out how to switch between an image by a mouseclick.
    >
    > The function should check if the image is on or off but it doesn´t work.
    > What´s wrong?[/color]

    document.images[image].src =
    (document.image s[image].src.indexOf("_ off")==-1) ?
    image + "_off.src" : image + "_on.src";

    JW



    Comment

    • Janwillem Borleffs

      #3
      Re: Switch between images


      "Janwillem Borleffs" <jw@jwscripts.c om> schreef in bericht
      news:3fa6cf31$0 $56502$1b62eedf @news.wanadoo.n l...[color=blue]
      >
      > document.images[image].src =
      > (document.image s[image].src.indexOf("_ off")==-1) ?
      > image + "_off.src" : image + "_on.src";
      >[/color]

      Error, sorry. Should be:

      document.images[image].src =
      (document.image s[image].src.indexOf("_ off")==-1) ?
      start_off.src : start_on.src;


      JW




      Comment

      • John

        #4
        Re: Switch between images

        Hoi Janwillem,


        Ik heb het al gezien. Het lag aan de puntkomma. Moet een dubbele punt zijn.

        Bedankt in ieder geval



        John

        htpp://members.home.nl/jpeskens


        "Janwillem Borleffs" <jw@jwscripts.c om> schreef in bericht news:3fa6cff9$0 $56492$1b62eedf @news.wanadoo.n l...[color=blue]
        >
        > "Janwillem Borleffs" <jw@jwscripts.c om> schreef in bericht
        > news:3fa6cf31$0 $56502$1b62eedf @news.wanadoo.n l...[color=green]
        > >
        > > document.images[image].src =
        > > (document.image s[image].src.indexOf("_ off")==-1) ?
        > > image + "_off.src" : image + "_on.src";
        > >[/color]
        >
        > Error, sorry. Should be:
        >
        > document.images[image].src =
        > (document.image s[image].src.indexOf("_ off")==-1) ?
        > start_off.src : start_on.src;
        >
        >
        > JW
        >
        >
        >
        >[/color]

        Comment

        Working...