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

Thread: JS getElementById

  1. #1
    Join Date
    Apr 2006
    Posts
    14

    Arrow JS getElementById

    Hey guys, just having a little trouble returning data that refers back to an image through JS.

    <script type="text/javascript" language="javascript">
    function showPic (whichpic) {
    if (document.getElementById) {
    document.getElementById('placeholder').src = whichpic.href;
    if (whichpic.title) {
    document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
    } else {
    document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
    }
    return false;
    } else {
    return true;
    }

    }
    </script>

    So what this does is when i click an image in the gallery it returns info from the title="" tag in the <a href of the image, the problem being that i need this info to be in a certain format. I almost need to return a table of info.

    Ive searched for scripts but i'm thinkin this is a little bit different from most.

    Any advice muchly appreciated folks

    Check it out if you feel 216.145.16.100~stitchworx/shirts.html

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    This is an awful chancey way to get or set nodeValue:

    document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;

    Are you looking for the title attr node?

    If you want the info from the title check
    document.getElementById('desc').title
    or document.getElementById('desc').getAttribute('title');

    But your function is set to return true or false...
    Last edited by mrhoo; 05-22-2006 at 10:46 PM.

  3. #3
    Join Date
    Apr 2006
    Posts
    14
    Cheers mrhoo, To say i was a noob with JS would be an Overstatment
    Eventually we found an alternative solution, which is ok but not as cool as i would have liked it.
    Thanks for the reply tho

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