title: Populate dropdown with data from database using jQuery
body: <p>Error is seen when i made a drop down list to populate data from Database.<br>
      Database : dtable<br>
  File in the template of hook_theme named : myModueForm_theme.tpl.php</p>
  
  <pre><code>&lt;?php
  $sel = "&lt;select  name=\"select1\" id=\"select1\"&gt;
          &lt;option value=\"\"&gt;Select...&lt;/option&gt;
          &lt;option value=\"data1\"&gt;data1&lt;/option&gt;
          &lt;option value=\"data2\"&gt;data2&lt;/option&gt;
          &lt;option value=\"data3\"&gt;data3&lt;/option&gt;
          &lt;option value=\"data4\"&gt;data4&lt;/option&gt;
      &lt;/select&gt;";
  echo "$sel";
  </code></pre>
  
  <p>?>  </p>
  
  <p>script tag starts  </p>
  
  <pre><code>jQuery("#select1").change( function(){
  if( jQuery(this).val() == "data1" ) {
  jQuery.ajax({
      type: "POST",
      url: "&lt;?php echo $base_url;?&gt;?q=search/data1",
      error: function(returnval) {
          alert("Failure");
      },
      success: function (returnval) {
          alert(returnval);
          alert("Sucess"); 
      }
  })
  }  
  });  
  </code></pre>
  
  <p>script tag ends</p>
  
  <p>The Module file which handles the database connection named : myModule.module  </p>
  
  <pre><code>$items['search/data1'] = array() 
  'title' =&gt; 'Add data', //page title
  'description' =&gt; 'form',
  'page callback' =&gt; 'search_data1',
  'page arguments' =&gt; array('access content'),
  'access callback' =&gt; TRUE
  </code></pre>
  
  <p>);</p>
  
  <p>// in the search_data function</p>
  
  <pre><code>function search_data1(){  
  
  $options="&lt;select  name=\"select2\" id=\"select2\"&gt;"; 
  $result = db_select('dtable', 'c')
      -&gt;fields('c')
      -&gt;execute() 
      -&gt;fetchAll();
  foreach ($result as $record) {
  $name = ($record-&gt;dt1);
      $options.="&lt;option value=\"$name\"&gt;".$name."&lt;/option&gt;"; 
      //alert(node);
  
  } 
  $options.= "&lt;/SELECT&gt;";
  return $options;
  </code></pre>
  
  <p>}</p>
  
  <p>What i want is<br>
  1-- please tell me where is the error &amp; how to solve<br>
  2-- i want to return the page back to the theme php page with the query result , but when i display back the return value from the module file, i get the whole HTML .</p>
  
  <p>Please help &amp; treat me as a beginner.Thanks in advance... /\</p>