Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   subroutines (http://www.velocityreviews.com/forums/t875825-subroutines.html)

Matthew Snape 02-12-2004 01:48 PM

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.dostuff(4)" This executed the sub ok. However I also
wanted to change the picture so I tried to do it like this:

function dostuff(picnumber) {
var picture = new Image;
picture.src ="alternativepic.gif";
document.picnumber.src = picture;
}

with the link like this:

<img src="a.gif" name="1"> <a href="#" onclick="dostuff(1)"> 1 </a>
<img src="a.gif" name="2"> <a href="#" onclick="dostuff(1)"> 2 </a>
<img src="a.gif" name="3"> <a href="#" onclick="dostuff(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 02-12-2004 03:02 PM

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(picnumber) {
document.images["pic"+picnumber].src="somethingelse.pic";
}

with the link like this:

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


Good luck,
Erwin Moller

Matthew Snape 02-12-2004 09:33 PM

Re: subroutines
 
Erwin Moller <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in message news:<402b956f$0$561$e4fe514c@news.xs4all.nl>...

Thank you very much, that worked.

> 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(picnumber) {
> document.images["pic"+picnumber].src="somethingelse.pic";
> }
>
> with the link like this:
>
> <img src="a.gif" name="pic1"> <a href="#" onclick="dostuff(1)"> 1 </a>
> <img src="a.gif" name="pic2"> <a href="#" onclick="dostuff(2)"> 2 </a>
> <img src="a.gif" name="pic3"> <a href="#" onclick="dostuff(3)"> 3 </a>
>
>
> Good luck,
> Erwin Moller


Erwin Moller 02-13-2004 09:40 AM

Re: subroutines
 
Matthew Snape wrote:

> Thank you very much, that worked.



Glad to help. :-)


All times are GMT. The time now is 11:34 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.