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

05-09-2004, 10: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){
return false;


<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.


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

JS can access that.

05-09-2004, 11:00 PM
Sounds like a possibility... But how do I do that? Could you give me an example?


Mr J
05-09-2004, 11:18 PM
Possibly one way would be like this

function showImage(sImage,txt){
return false;

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

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

05-09-2004, 11:25 PM
Great! Thanks alot!


05-09-2004, 11:44 PM
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){
return false;