dynamic images

T

twopeak

Hello

How do I get the alt tag of an image to appear in a textbox?
this is what I'm trying

function addsmile(image_name) {
var smiley;
smiley = document.image_name.alt; // <= THIS RULE SHOULD BE CORRECTED!!!!!
doc_content = document.form.bericht.value + smiley;
document.form.bericht.value = doc_content;
document.form.bericht.focus();
}

so when a user clicks a link, it sends the name of the image to the
function, and smiley should be the alt tag of the image!
if the variable image_name = "een"
then the line should be
smiley = document.een.alt;

thank you very much for any help!
 
L

Lasse Reichstein Nielsen

twopeak said:
Hello

How do I get the alt tag of an image to appear in a textbox?
this is what I'm trying

You should never assume that a named element can be accessed as just
"name" or "document.name". Some browsers allow it, others don't, but
it is always safer to go through the propert collections:
function addsmile(image_name) {
var smiley;
smiley = document.image_name.alt; // <= THIS RULE SHOULD BE CORRECTED!!!!!

<URL:http://jibbering.com/faq/#FAQ4_39>

smiley = document.images[image_name].alt;
doc_content = document.form.bericht.value + smiley;
document.form.bericht.value = doc_content;

var berichtElem = document.forms['form'].elements['bericht'];
berichtElem.value += smiley;
document.form.bericht.focus();
berichtEleme.focus();

}

so when a user clicks a link, it sends the name of the image to the
function, and smiley should be the alt tag of the image!
if the variable image_name = "een"
then the line should be
smiley = document.een.alt;

It should be
smiley = document.images.een.alt;
but since "een" is stored in the string called "image_name", it's
smiley = document.images[image_name].alt;

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,082
Messages
2,570,588
Members
47,209
Latest member
Ingeborg61

Latest Threads

Top