SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with retrieving innerHTML

    Here is my code:

    Code:
    function stick(prevID) {
    	var prevPic = document.getElementsByName(prevID);
    	var prevBox = document.getElementById("skuDisplay");	
    	var prevLink = document.getElementById("prevLink");
    	var prevName = prevPic.alt;
    	
    	prevBox.src = "prev/"+prevID+".jpg";
    	prevLink.href = "lg/"+prevID+".jpg";
    	prevBox.style.display = 'block';
    	document.getElementById("prev").innerHTML = prevName;
    };
    my problem is that the prevName is coming back as undefined. Does this not call the actual value of the alt attribute? If not how do you call the value of the alt attribute to display as the innerHTML of another object.

    Know it has to be simple, I just can't figure it out.

    Thanks in advance!

  2. #2
    SitePoint Zealot
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    prevPic is an array

  3. #3
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dogFang View Post
    prevPic is an array
    Don't mean to be a pain but could you please elaborate on that.

  4. #4
    SitePoint Zealot
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var prevPic = document.getElementsByName(prevID);
    Possibly you only have one element, or the first, with such a name, so
    Code:
    var prevName = prevPic[0].alt;


Bookmarks

Posting Permissions

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