SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    divs break ajax submit script

    I followed the tutorial here: http://www.captain.at/howto-ajax-form-post-get.php

    to post data from a form to php without refreshing the page. The problem is that the variables dont get passed if i try to use divs around the form input fields to stylize things. All i am doing is divs with class names. Why does this break things and what can i do get around it?

    Thanks,
    Mark

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    The script you are using is looking for the form elements using "obj.childNodes[i]"

    But when you wraped them in divs they can no longer be found using "obj.childNodes[i]" because the divs are in that section you would have to do something like:

    obj.childNodes[i].childNodes[x]

    But do not change them to what i just posted it won't work like that.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    The script you are using is looking for the form elements using "obj.childNodes[i]"

    But when you wraped them in divs they can no longer be found using "obj.childNodes[i]" because the divs are in that section you would have to do something like:

    obj.childNodes[i].childNodes[x]

    But do not change them to what i just posted it won't work like that.
    So if it wont work like the way you suggested, which way should i do it? =P

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Nested For loops, going though the first childNodes object then going though the childNodes object of the first. So...

    Code:
    var nodes = obj.childNodes;
    var l = nodes.length;
    
    for (var i = 0; i < l; i++) {
        if (nodes.tagName.toLower == 'div') {
            var children =  nodes.childNodes;
            // For loop...
        }
    
        // check for input elements like normal...
    }
    General Idea don't have a lot of time at the moment.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the attempts in helping me, but it doesnt seem to work and i havent got the slightest clue on how to modify your example to get it to work. It looks like the original tuturial was poorly written and us iterating through childnodes, instead of iterating over the just forms elements like it should.


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
  •