Can I use AJAX to add SUBMIT button or hidden INPUT into PHP form?
===

Hey guys I need my AJAX results to add fields to my FORM, or add a SUBMIT button to complete the form.

My AJAX results display in a DIV which is inside a standard HTML form (from a PHP file). When returned inside FORM tags, can AJAX results (as, say, hidden inputs) be included into the FORM POST??

I'm using a standard JavaScript (adapted from one posted for 'livesearch') to get AJAX results from AJAXresults.php which works fine - my AJAX results DO return OK, its just that my form doesn't work! The javascript is:

    function showResult(str)
    {
    if (str.length<4)
      {
      document.getElementById("suburbmatch").innerHTML="Type more than 4 letters...";
      return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }	
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("suburbmatch").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","AJAXresults.php?suburbtext="+str,true);
    xmlhttp.send();
    }

myphp.php includes the form like this: (note the DIV where AJAX results load, inside the FORM tags)

    <form action="myphp.php" method="POST">

     <input type="text" name="addressline1">
     <input type="text" name="addressline2">
     <input type="text" name="suburb" onkeyup="showResult(this.value)">

      <div id=suburbmatch></div>  // AJAX results display here

    </form>
    

AJAXresults.php includes a script that queries a database then returns the results as a hidden input field, and a SUBMIT button:

    echo ('<input type="hidden" name="suburbID" value="'.$row['ID'].'">');
    echo ('<input type="submit" name="submit" value="');
    echo ($row['suburb'].' '.$row['state'].' '.$row['zipcode']);
    echo ('"><br>');

This code is in the WHILE loop, so 'suburbs' matching the text typed into the "suburb" text input on myphp.php load up as a button displaying the suburb/state/zipcode. When you click it, it should SUBMIT the whole form on myphp.php including the hidden INPUT from the AJAX results.

I could return the results as text and hyperlinking the data with $_GET, like: (a href=myphp.php?result=x) but then it will refresh the page and reset the other form values :P