Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can a submit a form inside an Ajax window to itself?
    primarykey
    data
    text
    <p>How can I submit a form that's inside an Ajax div, to itself, without refreshing the entire page?</p> <p><strong>Here's my current form code that's inside the Ajax div:</strong></p> <pre><code>&lt;form name="searchLocations" method="POST"&gt; &lt;select name="locationName"&gt; &lt;?php $sql = mysql_query("SELECT locationName FROM tbl_locations ORDER BY locationName ASC"); while ($row = mysql_fetch_array($sql)){ echo "&lt;option value=\"owner1\"&gt;" . $row['locationName'] . "&lt;/option&gt;"; } ?&gt; &lt;/select&gt; &lt;input type="button" value="Load" id="searchingSubmit"&gt; &lt;/form&gt; </code></pre> <p><strong>and here's my ajax code:</strong> </p> <pre><code>&lt;script&gt; window.onload = function () { var everyone = document.getElementById('everyone'), searching = document.getElementById('searching'), searchingSubmit = document.getElementById('searchingSubmit'); everyone.onclick = function() { loadXMLDoc('indexEveryone'); everyone.className = 'filterOptionActive'; searching.className = 'filterOption'; } searching.onclick = function() { loadXMLDoc('indexSearching'); searching.className = 'filterOptionActive'; everyone.className = 'filterOption'; } searchingSubmit.onclick = function() { loadXMLDoc('indexSearchingSubmit'); } function loadXMLDoc(pageName) { var xmlhttp; 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 &amp;&amp; xmlhttp.status==200) { document.getElementById("leftCont").innerHTML=xmlhttp.responseText; } } function get_query(){ var url = location.href; var qs = url.substring(url.indexOf('?') + 1).split('&amp;'); for(var i = 0, result = {}; i &lt; qs.length; i++){ qs[i] = qs[i].split('='); result[qs[i][0]] = decodeURIComponent(qs[i][1]); } return result; } xmlhttp.open("GET","../browse/" + pageName + ".php?user=" + get_query()['user'],true); xmlhttp.send(); } } &lt;/script&gt; &lt;!-- ends Ajax script --&gt; </code></pre> <p>I, for some reason, get the impression I need to capture the POST variable somewhere inside the Ajax code so that it can be returned to the page.</p> <p>I'm not overly knowledgeable when it comes to Ajax and JavaScript so you might have to bare with me on this one.</p> <p>Here's an image to help explain:</p> <p><img src="https://i.stack.imgur.com/HoINP.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload