subroutines

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

    #1

    subroutines

    hi, I have recently tried to make a web page where there is a number
    of pictures each named with a number (1,2,3,4,5 etc). I then have
    links on the page which are supposed to change the picture. I know
    how to do this with the onclick event. However, I want to run several
    other things when the link is clicked. Therefore I put a subroutine
    that accepts the pictures name in the subroutine like this:
    onclick="top.do stuff(4)" This executed the sub ok. However I also
    wanted to change the picture so I tried to do it like this:

    function dostuff(picnumb er) {
    var picture = new Image;
    picture.src ="alternativepi c.gif";
    document.picnum ber.src = picture;
    }

    with the link like this:

    <img src="a.gif" name="1"> <a href="#" onclick="dostuf f(1)"> 1 </a>
    <img src="a.gif" name="2"> <a href="#" onclick="dostuf f(1)"> 2 </a>
    <img src="a.gif" name="3"> <a href="#" onclick="dostuf f(1)"> 3 </a>



    As you can see I want to be able to change the specific picture
    depending on the value of picnumber. Any ideas?
  • Erwin Moller

    #2
    Re: subroutines

    Hi,

    I am not sure if you can name your picture 1, 2, 3
    I think that a name should start with a letter or underscore.

    Try this:

    function dostuff(picnumb er) {
    document.images["pic"+picnu mber].src="something else.pic";
    }

    with the link like this:

    <img src="a.gif" name="pic1"> <a href="#" onclick="dostuf f(1)"> 1 </a>
    <img src="a.gif" name="pic2"> <a href="#" onclick="dostuf f(2)"> 2 </a>
    <img src="a.gif" name="pic3"> <a href="#" onclick="dostuf f(3)"> 3 </a>


    Good luck,
    Erwin Moller

    Comment

    • Matthew Snape

      #3
      Re: subroutines

      Erwin Moller <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in message news:<402b956f$ 0$561$e4fe514c@ news.xs4all.nl> ...

      Thank you very much, that worked.
      [color=blue]
      > Hi,
      >
      > I am not sure if you can name your picture 1, 2, 3
      > I think that a name should start with a letter or underscore.
      >
      > Try this:
      >
      > function dostuff(picnumb er) {
      > document.images["pic"+picnu mber].src="something else.pic";
      > }
      >
      > with the link like this:
      >
      > <img src="a.gif" name="pic1"> <a href="#" onclick="dostuf f(1)"> 1 </a>
      > <img src="a.gif" name="pic2"> <a href="#" onclick="dostuf f(2)"> 2 </a>
      > <img src="a.gif" name="pic3"> <a href="#" onclick="dostuf f(3)"> 3 </a>
      >
      >
      > Good luck,
      > Erwin Moller[/color]

      Comment

      • Erwin Moller

        #4
        Re: subroutines

        Matthew Snape wrote:
        [color=blue]
        > Thank you very much, that worked.[/color]


        Glad to help. :-)

        Comment

        Working...