dynamic images

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • twopeak

    dynamic images

    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.b ericht.value + smiley;
    document.form.b ericht.value = doc_content;
    document.form.b ericht.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.al t;

    thank you very much for any help!




  • Lasse Reichstein Nielsen

    #2
    Re: dynamic images

    "twopeak" <twopeak@pandor a.be> writes:
    [color=blue]
    > Hello
    >
    > How do I get the alt tag of an image to appear in a textbox?
    > this is what I'm trying[/color]

    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:
    [color=blue]
    > function addsmile(image_ name) {
    > var smiley;
    > smiley = document.image_ name.alt; // <= THIS RULE SHOULD BE CORRECTED!!!!![/color]

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

    smiley = document.images[image_name].alt;
    [color=blue]
    > doc_content = document.form.b ericht.value + smiley;
    > document.form.b ericht.value = doc_content;[/color]

    var berichtElem = document.forms['form'].elements['bericht'];
    berichtElem.val ue += smiley;
    [color=blue]
    > document.form.b ericht.focus();[/color]

    berichtEleme.fo cus();
    [color=blue]
    > }
    >
    > 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.al t;[/color]

    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
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...