Jump to content

AJAX GET request from behind a table


vincea

Recommended Posts

Hey everyone,

 

I always use the AJAX GET request to then make a request to a PHP document.. works great but before I haven't done it with the form behind a table. Here is an example of what I mean.

 

the html:

 

<form name="blah" id="blah">

<table>

<tr>

<td><input type="text" name="blah2" id="blah2"></td>

</tr>

<tr>

<td><input type="button" name="submitit" value="submitme!" onclick="get(this.parentNode);"></td>

</tr>

</table>

</form>

 

the js:

  
function get(obj) {
      var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         if (obj.childNodes[i].tagName == "TEXTAREA") {
            var sel = obj.childNodes[i];
            getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
         }
      makeRequest('thephp.php', getstr);
  }
   }

 

I can never get this to work from behind a table. Mostly because the childNodes picks up the table Nodes and not the form Nodes.

 

Any idea is greatly appreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.