...

View Full Version : Sending variables in onClick commands (?)



zioneer
05-09-2004, 11:33 PM
I am a VBScript guy with a JavaScript problem. I have a
<a href="pic/image_20.jpg" onclick="return showImage(this.href);">

-tag that loads a large image with the help of:

function showImage(sImage){
document.getElementById('galleryimage').src=sImage;
return false;
}

and

<img src="x.gif" id="galleryimage">

But I want a specifik text under each image too.

How do I solve that? I add the text as a variable in each link? How? Please note, I have as good as NO knowledge of JScript.

/Johan

escaperanger
05-09-2004, 11:51 PM
Can you place the text in the alt property of the <img>?

JS can access that.

zioneer
05-10-2004, 12:00 AM
Sounds like a possibility... But how do I do that? Could you give me an example?

/johan

Mr J
05-10-2004, 12:18 AM
Possibly one way would be like this


<script>
function showImage(sImage,txt){
document.getElementById('galleryimage').src=sImage;
document.getElementById('text').innerHTML=txt
return false;
}
</script>


<img src="x.gif" id="galleryimage">
<div id="text"></div>

<a href="pic/image_20.jpg" onclick="return showImage(this.href,'Hello World')">

zioneer
05-10-2004, 12:25 AM
Great! Thanks alot!

/Johan

escaperanger
05-10-2004, 12:44 AM
I mis-read the problem the first time. This might work, depending on the number of images you want this to work with.


Create an array to hold some objects you will create
var my_objs = new Array();

Create an Image object that loads the image off-screen for fast image swapping when the user clicks the link, and will hold all the info each image needs
my_objs['monkey'] = new Image();
my_objs['monkey'].src = 'ring_phone.gif';
my_objs['monkey'].text = '432424';
my_objs['monkey'].whatever = 'gdfvdfgdf';

(You could use a number instead of a name)
my_objs[0] = new Image();


Change your link
<a href="javascript:;" onclick="return showImage('monkey');">

function showImage(name){
document.getElementById('galleryimage').src=my_objs[name].src;
return false;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum