Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax with 2 drop down menus
    text
    copied!<p>I have 2 drop down menus. After a user has selected an option from each I wish for an answer to be generated by AJAX. I can do this with just one drop down using the example found here:</p> <p><a href="http://www.w3schools.com/php/php_ajax_database.asp" rel="nofollow">http://www.w3schools.com/php/php_ajax_database.asp</a></p> <p>I have followed some suggestions to try and modify the script for 2 dropdowns, however I have been unsuccessful. It seems that the data is not being posted to the getuser.php page.</p> <p>My HTML code page is as follows:</p> <pre><code>&lt;?php require('includes/application_top.php'); ?&gt; &lt;!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function showUser(current_size, current_shoe) { if (str=="") { document.getElementById("txtHint").innerHTML=""; 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 &amp;&amp; xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getuser.php?size="+current_size"&amp;shoe="current_shoe); xmlhttp.send(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;?php $query = "SELECT products_name, products_shoe_size FROM products_description WHERE language_id = 1 and products_shoe_size != '' "; // Execute it, or return the error message if there's a problem. $result = mysql_query($query) or die(mysql_error()); ?&gt; &lt;form&gt; &lt;?php $dropdown = "&lt;select name='current_shoe' id='current_shoe'&gt;&lt;option value=''&gt;Select the model of your current shoes:&lt;/option&gt;"; while($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n&lt;option value='{$row['products_shoe_size']}'&gt;{$row['products_name']}&lt;/option&gt;"; } $dropdown .= "\r\n&lt;/select&gt;"; echo $dropdown; ?&gt; &lt;select name="current_size" id="current_size" onchange="showUser(Document.getElementById('current_size').value, Document.getElementById('current_shoe').value)"&gt; &lt;option value=""&gt;Select the size of your current shoes:&lt;/option&gt; &lt;option value="2"&gt;2&lt;/option&gt; &lt;option value="2.5"&gt;2.5&lt;/option&gt; &lt;option value="3"&gt;3&lt;/option&gt; &lt;option value="3.5"&gt;3.5&lt;/option&gt; &lt;option value="4"&gt;4&lt;/option&gt; &lt;option value="4.5"&gt;4.5&lt;/option&gt; &lt;option value="5"&gt;5&lt;/option&gt; &lt;option value="5.5"&gt;5.5&lt;/option&gt; &lt;option value="6"&gt;6&lt;/option&gt; &lt;option value="6.5"&gt;6.5&lt;/option&gt; &lt;option value="7"&gt;7&lt;/option&gt; &lt;option value="7.5"&gt;7.5&lt;/option&gt; &lt;option value="8"&gt;8&lt;/option&gt; &lt;option value="8.5"&gt;8.5&lt;/option&gt; &lt;option value="9"&gt;9&lt;/option&gt; &lt;option value="9.5"&gt;9.5&lt;/option&gt; &lt;option value="10"&gt;10&lt;/option&gt; &lt;option value="10.5"&gt;10.5&lt;/option&gt; &lt;option value="11"&gt;11&lt;/option&gt; &lt;option value="11.5"&gt;11.5&lt;/option&gt; &lt;option value="12"&gt;12&lt;/option&gt; &lt;option value="12.5"&gt;12.5&lt;/option&gt; &lt;option value="13"&gt;13&lt;/option&gt; &lt;/select&gt; &lt;/form&gt; &lt;br /&gt; &lt;div id="txtHint"&gt;&lt;b&gt;Sizing info will be listed here.&lt;/b&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?&gt; </code></pre> <p>I'm guessing that the problem can be found in one of these lines of code:</p> <pre><code>function showUser(current_size, current_shoe) xmlhttp.open("GET","getuser.php?size="+current_size"&amp;shoe="current_shoe); &lt;select name="current_size" id="current_size" onchange="showUser(Document.getElementById('current_size').value, Document.getElementById('current_shoe').value)"&gt; </code></pre> <p>If anyone has any idea what I'm doing wrong I will be eternally grateful. I'm fast running out of hair. </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