Note that there are some explanatory texts on larger screens.

plurals
  1. POsend answer to server, and retrieve relevant array from server back for next input options
    text
    copied!<p>I'm trying to get the following to work: I would like to send an answer to a drop-down menu question to a php script, which in turn will give me back a new selection from the database. I then want to use this new selection to change the available input options in a secondary drop-down menu</p> <p>The end goal is to limit the selection options from around 200 (day care centers) to about 15, by providing a preliminary limitation (chosing your municipality)</p> <p>for reference "gem(eente)" is municipality</p> <p>stripped down the javascript/ajax part that I have so far is this:</p> <pre><code>function loadXMLDoc(str) { 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("gemeente").innerHTML=xmlhttp.responseText; } } xmlhttp.open("POST","http:www.doenwatikkan.nl/jeroen/dynamic.php",true); xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp.send(gem); alert(gem) } </code></pre> <p>the php part is this</p> <pre><code>&lt;?php include 'dbconnection.php'; $gem=$_POST["gem"]; $gennam=mysql_query("SELECT * FROM psz WHERE Gemeente='$gem'"); echo "ik ben in dit php script geweest"; $test="willekeurige string"; ?&gt; </code></pre> <p>and the relevant html/php part is the following:</p> <pre><code>&lt;select name="pszplaats" id="gemeente" onchange="fdisplay();loadXMLDoc(this.value)"&gt; &lt;?php while($row=mysql_fetch_array($selectgem)){?&gt; &lt;option value="&lt;?php echo $row['Gemeente']; ?&gt;"&gt;&lt;?php echo $row['Gemeente'];?&gt; &lt;/option&gt; &lt;?php } ?&gt; &lt;/select&gt; &lt;select name="psznaam" id="test" style="display:none"&gt; &lt;?php while($row=mysql_fetch_array($gennam)){?&gt; &lt;option value="&lt;?php echo $row['NaamPSZ']; ?&gt;"&gt;&lt;?php echo $row['NaamPSZ'];?&gt; &lt;/option&gt; &lt;?php } ?&gt; &lt;/select&gt; </code></pre> <p>the alert(gem) part in the javascript works, so if people select an option for minucupality, it shows up on screen, but the "echo" in the php part doesn't show anything, so Im thinking the ajax doesn't look at my php properly. </p> <p>Could anybody please tell me what idiotic mistake I am making, because I can't figure it out. thanks in advance!</p>
 

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