views:

642

answers:

1

I'm trying to setup a search page which performs two separate kinds of search using two radio buttons which the user can toggle to indicate what it is their searching for.

The second search type I'd decided to use a jquery autocomplete script, because there's a relatively small set of searchable items (~213) and this would produce an attractive and consistent way to access the data.

To do this I'd wanted to setup the script, but trigger it to only be used when the user selected the second radio button, which I've achieved (albeit, questionably) by binding a portion to a click even, eg:

                    $(document).ready(function() {
                    $( "#selector" ).click(
                    function( objEvent ){
                        $("#name").autocompleteArray(
                        [
                            "Alternative/Punk","Blues","Classical","Country/Folk","Electronic","Hip-Hop/R&B","International","Jazz","etc"
                        ],
                        {
                            delay:10,
                            minChars:1,
                            matchSubset:1,
                            onItemSelect:selectItem,
                            onFindValue:findValue,
                            autoFill:true,
                            maxItemsToShow:10
                        }
                    );
                    }
                );
                    $( "#unselector" ).click(
                    function( objEvent ){
                        //Do something
                    }
                );
                });

So before laughing too hard, it does do what I'd wanted (I'm crap with js, and only recently began to learn PHP). The problem is I'd like to setup that second selector (#unselector) to stop/disable/hide/unbind/whatever the autocomplete function should the user toggle the first radio button after having toggled the second (change their mind, just clicking around, etc).

Obviously the way it works now once the second radio is selected the autocomplete script is setup and anything typed into the search box will be presented with the suggestions, no matter which button is eventually selected.

You can see the script in action here:

www.lfmseek.com/rss/

It's just a small app that generates rss links for emusic users (I'm a user myself).

The script itself can be found at the authors page here (although everything embedded as usual in the page above):

www.pengoworks.com/workshop/jquery/autocomplete.htm

Any help would really be appreciated. I have the distinct feeling this should be simple, but my relationship with anything generally javascript related tends to be...anything but. :-)

And thanks a lot for you time.

+2  A: 

You can simply unbind all events from 'name'.

$( "#unselector" ).click(function( objEvent ){
   $("#name").unbind();
});
Shaun Humphries
Thank you, this works perfectly. You just totally made my afternoon. Thank you so much. :-)
Glad I could help.
Shaun Humphries