Dynamically change select dropdown value using jquery ajax
<p>I am using two dropdowns in a form for searching. The second dropdown value will change based on the selection of the first one. The ajax request goes but somehow not returning any value from the php script. Any suggestions for change in code?</p>

<p>search.php</p>

<pre><code>&lt;select name="shop_name" id="shop_name"&gt;
                  &lt;option value="blank"&gt;Select one&lt;/option&gt;
                  &lt;?php
                  $searchItem = new dbhandler();
                  $shopData = $searchItem-&gt;all_data('food_shops');
                  $i = 0;
                  foreach($shopData as $sd) {
                    ?&gt;
                    &lt;option value="&lt;?php echo $shopData[$i]-&gt;r_id; ?&gt;"&gt;&lt;?php echo $shopData[$i]-&gt;name; ?&gt;&lt;/option&gt;
                    &lt;?php $i++; } ?&gt;
 &lt;/select&gt;
</code></pre>

<p>script.js</p>

<pre><code>&lt;script type="text/javascript"&gt;
$(document).ready(function()
{
  $("#shop_name").change(function()
{
  var id=$(this).val();
  var dataString = 'id=' + id;
$.ajax
({
  type: "GET",
  url: "dynamic_select.php",
  data: dataString,
  success: function(data)
  {
    $("#location").html(data);
  }
  });

  });

  });
</code></pre>

<p></p>

<p>dynamic_select.php</p>

<pre><code>&lt;?php

if($_GET['id']) {

  $crs = $_GET['id'];
?&gt;

  &lt;select name="location" id="location"&gt;
&lt;?php
  $searchItem = new dbhandler();
  $searchItem-&gt;find('food_shops' , 'r_id', $crs);
  $data = $searchItem-&gt;data();
  $j = 0;
  foreach($data as $d) {
    ?&gt;
    &lt;option value="&lt;?php echo $data[$j]-&gt;address; ?&gt;"&gt;&lt;?php echo $data[$j]-&gt;address; ?&gt;&lt;/option&gt;
  &lt;/select&gt;
&lt;?php $j++; } } ?&gt;
</code></pre>

<p>The all_data() queries <code>SELECT * FROM table_name</code>
and find() queries <code>SELECT * FROM table_name WHERE r_id = $crs</code></p>