SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict Bravogolf's Avatar
    Join Date
    Aug 2004
    Location
    All over really :)
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Automatic ID in document.getElementById

    Hi all, am using an ajax function on my site and the JS code works fine when I hard code what DIV tag to use. For example:

    Code JavaScript:
    document.getElementById("ajax").innerHTML=flickupdate.responseText;

    However, if wanted to pass the ID to use, or even hard code for demo purposes the DIV tag in an ID, it doesn't work:

    Code JavaScript:
    var ajaxid="ajax";
    document.getElementById(ajaxid).innerHTML=flickupdate.responseText;

    What am I doing wrong?
    Last edited by Bravogolf; Dec 26, 2008 at 04:14.

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're not passing the 'ajaxid' string in the second snippet, shouldn't it be this:

    Code JavaScript:
    document.getElementById(ajaxid).innerHTML = flickupdate.responseText;
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Addict Bravogolf's Avatar
    Join Date
    Aug 2004
    Location
    All over really :)
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, sorry, that was a typo in my post that I've corrected. Still doesn't work, am afraid. If I try passing the ID as variable I get the element id is null or undefined.

  4. #4
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, this should work perfectly, are you sure you have it exactly like this? -

    Code JavaScript:
    var ajaxid="ajax";
    document.getElementById(ajaxid).innerHTML=flickupdate.responseText;

    The only reason it wouldn't work is if there is no element on the page with an ID of "ajax"...
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)


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
  •