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
https://forums.phpfreaks.com/topic/50528-ajax-get-request-from-behind-a-table/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.