SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DOM issues need help accessing a span

    Okay my problem is I have a span that needs to updated via innerHTML from an AJAX call.

    Problem:

    document.getElementById("x"); isn't working because it's buried in a form inside of a division. I can access the division using the above method but nothing inside of it. I haven't studied access to the DOM since I was like 12 so my knowledge about it is 10 years old at least. So if someone could give me even a slight clue about how to get at that span I would greatly appreciate it.

    Thank you.
    -Frost

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well:
    - add an ID to the span and use getElementById OR
    - know the DOM layout inside your known DIV, and walk the DOM tree; example:
    Code:
    // get the second "span" contained in the first "p" contained in "myDiv"
    var mySpan = document.getElementById("myDiv").getElementsByTagName("p")[0].getElementsByTagName("span")[1];
    - go through all the "span"s of the document looking for something specific about your one
    Code:
    var spans = document.body.getElementsByTagName("span");
    for (var i=0; i < spans.length; i++) {
      if (spans[i].className == "superspan") {
        // do something with spans[i]
      }
    }
    There are other ways, see if that gets you started.

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks that helps a little bit... I managed to get it working the other day but it uses the old long drawn out document.all.this.document.all.that method. The way you posted cleans things up a bit... I've run into another wierd problem now... for some reason the ajax call wont' have off form values that consist of the letter j by itself or the word this or lots of other things and it's really killing my server side script.

    HTML:

    Code:
    function ajaxEmailcheck(str) {
    
    ...normal try and catch statement...
    
     var url = "/ajax/checkemail.php?emal=" + str;
    
     xmlHttp.onreadystatechanged = function() {... update code ...}
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
    
    }
    That function works fine and so does the text field in the html. which is set to run above function
    Code:
    onChange="ajaxEmailcheck(this.value)"
    This works as well for things like jjj, fff, aaa, but not for jjackson, this, the letter j, the letter t and things like that. I know they aren't getting handed off because I'm having the php script echo the variable it recieved along with the taken or available message from the ajax response.

    Am I missing something?


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
  •