Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay data after selected item
    text
    copied!<p>First Id like to thank everyone for such positive response on my previous question.</p> <p>Now I got another question I need help with.</p> <p>I have a dropdown menu with a list of items. The list is generated inside while loop. Here is the code:</p> <pre><code>$query = "SELECT Key, Short FROM product WHERE Active = 1 OR Short LIKE 'Blue%'"; $run = mysql_query($query) or die(mysql_error()); echo 'Product: &lt;br /&gt;'; ?&gt; &lt;select id="select2" name="select2"&gt; &lt;?php $ids = 0; echo "&lt;option selected='selected'&gt;-Select product-&lt;/option&gt;"; while($rows = mysql_fetch_assoc($run)) { echo "&lt;option value=$ids&gt;".$rows['Short']."&lt;/option&gt;"; $ids++; } ?&gt; &lt;/select&gt;&lt;br /&gt;&lt;br /&gt; </code></pre> <p>Now what I need to do is create another dropdown menu below this one and show contracts depending on which option they selected from dropdown menu. Each item they select also have a number called Key. Now inside another table called contracts I have stored all contracts with the same value Key. So...in the second dropdown menu I have to show the contracts based on the key they selected with the item in the first dropdown menu.</p> <p>I really hope it is clear enough to understand, I am a little confused.</p> <p>Update: Ok, here is new code:</p> <p>index.php </p> <pre><code>$("select#select2").change(function(){ $.ajax({ type: "GET", url: "process.php", data: "selected_key=" + $(this).val(), success: function(result) { $("select#text2").html(result); } }); }); &lt;/script&gt; &lt;select id="text2" name="text2"&gt; &lt;/select&gt; </code></pre> <p>And here is my process.php</p> <pre><code>&lt;?php ## URL_TO_GET_CONTRACTS_FOR_KEY ## $selectedKey = $_GET['selected_key']; $query = "SELECT * FROM contacts WHERE Key = '".$selectedKey."'"; $run = mysql_query($query); while($row = mysql_fetch_assoc($run)) { echo "&lt;option value='..'&gt;..&lt;/option&gt;"; } ?&gt; </code></pre> <p>But I cant see anything displayed in my text2 dropdown menu.</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