Hi ? I need a java script code that does the following:
When i click an image, it will change and in its place, second picture will appear. And when i click that second picture also the first picture will appear… How can i do that?
@crazycoderMar 12.2006 — #Here, this is if you want each image to replace the other, which is I think what you want to do. That makes it a little more complex than if you have two seperate images, but it's still really easy. Put this in your head command:
[CODE] <script language="JavaScript"> var i = 0; function bla() { if (i == 0) { document.image.src='source.gif'; i = 1; } else { document.image.src='source2.gif'; i = 0; } } </script>[/CODE]
@hansfromhollandMar 12.2006 — #I do react upon your question because it looks a bit like my question a while back. I have a page with a lot of small pictures and each of those pictures is clickable and leads to a magnified version in another page. Then you can go through all the enlargements by simply pressing the > or < on your keyboard. Clicking on an enlargement brings you back to the page with the small pictures.
If you want to see this in action, go [URL=http://www.hhdesign.nl/example/example.htm]here.[/URL]
@Sleep_ModeauthorMar 12.2006 — #Thank you hans. But i can not see any javascript here. Is there anyone that will answer my question about passing the parameter to this function?
and it jumps to this file which shows the second picture in the array: the pictures of this array are called pic_1.jpg, pic_2.jpg, pic_3.jpg and pic_4.jpg.
[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>example</title> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <script language="JavaScript"> <!-- var key = new Array(); key[','] = -1; key['<'] = key[',']; key['.'] = +1; key['>'] = key['.']; var photo = new Array( 1,2,3,4,''); var max = photo.length - 2; var nr = 0; function show(x) { nr += x; if (nr < 0) nr = max; if (nr > max) nr = 0; document.thePhoto.src = 'pic_' + photo[nr] + '.jpg'; }; function firstPhoto() { var ls = unescape(location.search).replace(/?/g,''); for (var i = 0; i < max+1; i++) if (ls == photo[i]) nr = i; show(0); }; function getKey(keyStroke) { if (typeof(event) == 'object') { eventChooser = event.keyCode; } else if (typeof(keyStroke) == 'object') { eventChooser = keyStroke.which; } else { eventChooser = 0; }; var which = String.fromCharCode(eventChooser).toLowerCase(); if (typeof(key[which]) == 'number') show(key[which]); }; document.onkeypress = getKey; // --> </script> </head> <body scroll="no" onload="firstPhoto()"> <center> <a href="JavaScript:history.back();"><img name="thePhoto" src="#" border="0" width="100%" title="Click left to go back or type < for the previous or > for the next picture."></a><br> <br> <a href="JavaScript:show(-1);"></a><a href="JavaScript:show(+1);"></a> </center> </body> </html>[/code]