Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:24:38+00:00 2026-06-01T23:24:38+00:00

I am new to jQuery and am having some trouble figuring something out. I

  • 0

I am new to jQuery and am having some trouble figuring something out.

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:

$(function(){
    $('#intext').autocomplete('get-data.php?mode=sql', {
        width: 400,
        max: 5,
        selectFirst: false
    });
});

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.

So my question is, how can I enable this by clicking one radio button, and disable it by clicking the second radio button?

EDIT

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.

EDIT 2

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:

News: <input type="radio" class="myRadio" name="search_type" value="news" checked="checked" onclick="this.form.action='/search.php';" />
Media Gallery: <input type="radio" class="myRadio" name="search_type" value="media" onclick="this.form.action='/media.php';" />
<input id="intext" class="txt" type="text" name="searchterms" />

I have the following code in the script that runs on each page:

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
    });

}

This does not seem to work, and the Error Console in Firefox doesn’t show any errors.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:24:40+00:00Added an answer on June 1, 2026 at 11:24 pm

    Assuming this is the jQueryUI autocomplete, you can use $el.autocomplete("destroy") to remove the autocomplete function.

    addAutoComplete($("#intext")); // on load
    
    $(".myRadio").change(function() {
        if ($(this).val() == "a") {
            if (!$("#intext").hasClass("ui-autocomplete-input"))
                addAutoComplete($("#intext"));
        }
        else {
            $("#intext").autocomplete('destroy')
        }
    });
    
    function addAutoComplete($el) { 
        $el.autocomplete('get-data.php?mode=sql', {
            width: 400,
            max: 5,
            selectFirst: false
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to JQuery and I'm having some trouble with the Clone() function. My
I'm new to jquery and javascript in general so I'm having some trouble figuring
I'm very new to jQuery and having some issues figuring out stuff here :)
I am having some trouble setting up FancyBox, I am somewhat new to jQuery.
I'm very new to JQuery, and I'm having some trouble understanding how to do
I'm fairly new to jQuery and I'm having trouble with an animation that I'd
I'm having some trouble with a few routines that are using jQuery to dynamically
I'm having trouble figuring out Razor syntax and how variable scope works. I'm new
I'm having some trouble with IE6 and jQuery UI. I have a popup dialog
I'm having trouble figuring out how to display some return JSON objects. My script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.