title: JQuery autocomplete based on select option value
body: <p>I am very very new to JQuery and Javascript. I have implemented autocomplete functionality that retrieves the data from remote datasource( Mysql + PHP) using jQuery Demo. 
  I am stuck at the part where the mysql query triggered by the php script is binded to the drop down menu option. </p>
  
  <p>So if I select "comments" from one of the option value, how do I bind it to the search textbox with id="search_term".  </p>
  
  <pre><code>&lt;label&gt;Select Search parameter:
      &lt;select id="search_parameter" name="search_parameter"&gt;
          &lt;option value="Sample name"&gt;Sample Name&lt;/option&gt;
          &lt;option value="Location name"&gt;Location Name&lt;/option&gt;
          &lt;option value="comments"&gt;Comments&lt;/option&gt;
      &lt;/select&gt;
  &lt;/label&gt;
  
  &lt;label&gt; Search Term:&lt;input type="text" id="search_term" required name="search_term" maxlength=30&gt;&lt;/label&gt;
  </code></pre>
  
  <p>Now if I select option value as "comments" it should trigger the PHP script that queries the comment field. But I am not sure how do I get the conditional statement into JQuery. I am not getting success with </p>
  
  <pre><code>$(function(){
      $('#search_parameter').change(function(){
          if (this.value == "comments") {
              jQuery(document).ready(function($){
                  $('#search_term').autocomplete({source:'search_comments.php', minLength:2});
              });
          else if( this.value =="Sample name") {
              jQuery(document).ready(function($){
                  $('#search_term').autocomplete({source:'search_sample_name.php', minLength:2});
              });
  }
  </code></pre>
  
  <p>I am not sure if this is the right approach. I apologize if this question is not  worthy of stackoverflow.com.
  Thank you</p>