dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: Returning the alt name of an image that is clicked on

  1. #1
    Join Date
    Aug 2009
    Posts
    5

    Returning the alt name of an image that is clicked on

    I have set up a number of images using javascript.

    When one is clicked on i have used onclick to call a function. (same function for all images)

    Is there any notation to refer to the active/selected image, something like this.element (new to javascript so dont know the notation)

    I want the function to be able to use the alt value of the image (different for each image) clicked.

    Have searched high and low for this but just keep getting things like how to add an alt value to your image.

    Even if i just had the notation i could find some examples and play.


    ty
    paule

  2. #2
    Join Date
    Aug 2009
    Posts
    5
    I have been looking a bit closer, i can set up an array as the images open on a loop, they will be the only images on the page, is there a way to reference the image by index number?

  3. #3
    Join Date
    Aug 2007
    Posts
    3,767
    this.alt.
    If you show the code, we can show you how to set up Event delegation.

  4. #4
    Join Date
    Aug 2009
    Posts
    5
    Cheers for the quick response Declan,

    I think i will have a read through that link and have a look for other stuff online.

    New to this and i wont learn by copying and pasting.

    I can actually set it up using an array with the values rather than the alt tag, are arrays seen as ok in web design?

  5. #5
    Join Date
    Aug 2009
    Posts
    5
    I cant seem to work it out.

    here is the code im attempting to use

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <?xml version="1.0" encoding="UTF-8"?>
    <html>
    <head>
    <link rel="stylesheet" href="simple.css" type="text/css" media="screen" />
    
    <script type="text/javascript">
    var i;
    var x;
    var passablebooks;
    var testing = new Array();
    </script>
    <script type="text/javascript">
    function whichElement()
     {		
    		i = 6
    		passablebooks=(testing[i])
    		alert(passablebooks);
    		parent.passableinfo = testing[i];
       
       }
    </script>
    </head>
    <body>
    <script type="text/javascript">
    function handleJson(json) {
    var bookurl;
    var bookdescription;
    x=Math.ceil(json.feed.openSearch$totalResults.$t/20);
    for (i=0;i<=20;i++)
    {
    booktitle=json.feed.entry[i].title.$t;
    bookauthor=json.feed.entry[i].dc$creator[0].$t;
    bookurl=json.feed.entry[i].link[0].href;
    document.write('<a href="info.html" target="Info" onclick="javascript: void"><img src="' + bookurl + '"alt="http://books.google.com/books/feeds/volumes/' + json.feed.entry[i].dc$identifier[0].$t + '?&run=1&alt=json-in-script&callback=handlequery" width="75px" height="120px" onclick="whichElement(testing);" title="' + booktitle + ' - ' + bookauthor + '" />');
    testing[i] = json.feed.entry[i].dc$identifier[0].$t;
    }
    }
    </script>

    I have written the script so it passes the variable to another frame.

    These lines are just for me to check
    i = 6
    passablebooks=(testing[i])
    alert(passablebooks);

    I will never know what the alt tag is going to be so need to either reference it by the image that was selected or by an array value that will be 1 less than the image index.
    Last edited by paulepool; 08-19-2009 at 02:58 PM.

  6. #6
    Join Date
    Aug 2009
    Posts
    5
    This is now sorted, new to all this stuff and was putting this.alt in the wrong place, and for my next Q..........

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles