title: Toggle jQuery function on and off
body: <p>I am new to jQuery and am having some trouble figuring something out.</p>
  
  <p>I have this function that is called at the bottom of the page to attach an auto-complete feature to a text box, this part is working fine. Here is the code that is called to enable the auto-complete:</p>
  
  <pre><code>$(function(){
      $('#intext').autocomplete('get-data.php?mode=sql', {
          width: 400,
          max: 5,
          selectFirst: false
      });
  });
  </code></pre>
  
  <p>However the search box contains two radio buttons for two different types of searches. The auto-complete feature should only be available for one type of search.</p>
  
  <p>So my question is, how can I enable this by clicking one radio button, and disable it by clicking the second radio button?</p>
  
  <p>EDIT</p>
  
  <p>The auto-complete script has a .autocomplete( "disable" ) method, but I don't know how to enable/disable that based on which radio button is checked.</p>
  
  <p>EDIT 2</p>
  
  <p>I am trying to get the method suggested by "Rory McCrossan" to work, as I am using jQuery UI Autocomplete. Here's the code for my radio buttons and search box:</p>
  
  <pre><code>News: &lt;input type="radio" class="myRadio" name="search_type" value="news" checked="checked" onclick="this.form.action='/search.php';" /&gt;
  Media Gallery: &lt;input type="radio" class="myRadio" name="search_type" value="media" onclick="this.form.action='/media.php';" /&gt;
  &lt;input id="intext" class="txt" type="text" name="searchterms" /&gt;
  </code></pre>
  
  <p>I have the following code in the script that runs on each page:</p>
  
  <pre><code>addAutoComplete($("#intext"));
  
  $(".myRadio").change(function() {
      if ($(this).val() == "news") {
          if (!$("#intext").hasClass("ui-autocomplete-input"))
              addAutoComplete($("#intext"));
      }
      else {
          $("#intext").autocomplete('destroy')
      }
  });
  
  
  function addAutoComplete($el) {
      $('#intext').autocomplete('autocomplete-data.php?mode=sql', {
          width: 400,
          max: 5,
          selectFirst: false
      });
  
  }
  </code></pre>
  
  <p>This does not seem to work, and the Error Console in Firefox doesn't show any errors.</p>