JQuery AutoComplete extraParams and CheckBoxes

I love jQuery. I work with it quite a lot on various projects. One of the coolest features in my humble opinion is AutoComplete. There are a ton of different plugins you can work with, some are variations of others, but for the most part, they work pretty darn good out of the box.

I have been trying unsuccessfully over the past hour or so to pass in the value of a checkbox as a parameter to my AutoComplete plugin as follows:

1
2
3
4
5
cacheLength:0,
minChars:2,
max:20,
autoFill:false,
extraParams: { active : $('input[name=status]').is(':checked') }

Now the issue I was encountering was regardless of what the state of the checkbox was, checked or unchecked, the AutoComplete plugin always returned it’s initial value. So if by default it was unchecked, it always returned false. If by default it was checked, it always returned true.

After a bit of digging, I finally stumbled across this site that explains that the value is locked in once the AutoComplete plugin is initialized: http://stackoverflow.com/questions/1216222/jquery-passing-checkbox-values

So to solve the issue:

1
2
3
4
5
6
7
8
9
cacheLength:0,
minChars:2,
max:20,
autoFill:false,
extraParams: {
    active : function() { 
        return $('input[name=status]').is(':checked'); 
    }
}

Awesome! Thanks to Stack Overflow and redsquare!

Trackbacks/Pingbacks

  1. 15+ jQuery Autocomplete Plugins & Tutorials | Choose Daily - September 17, 2009

    […] JQuery Autocomplete extraParams and CheckBoxes This post covers a problem where the developer was having problems passing the value of a checkbox as a parameter to their AutoComplete plugin. The problem was that the checkbox always returned the initial state value rather than the selected value. If you’ve run into this or are dealing with it now, this post should help you out. […]

  2. ContinousLearner: Links (9/17/2009) | Astha - September 17, 2009

    […] JQuery AutoComplete extraParams and CheckBoxes […]

  3. 10+ Best jQuery Autocomplete Plugins & Tutorials | WebScriptPlus.com - April 13, 2011

    […] 9.JQuery Autocomplete extraParams and CheckBoxes This post covers a problem where the developer was having problems passing the value of a checkbox as a parameter to their AutoComplete plugin. The problem was that the checkbox always returned the initial state value rather than the selected value. If you’ve run into this or are dealing with it now, this post should help you out. […]

  4. Top 15 jQuery Autocomplete Plugins & Tutorials | 9Tricks.Com - Tips - Tricks - Tutorials - August 21, 2011

    […] JQuery Autocomplete extraParams and CheckBoxes This post covers a problem where the developer was having problems passing the value of a checkbox as a parameter to their AutoComplete plugin. The problem was that the checkbox always returned the initial state value rather than the selected value. If you’ve run into this or are dealing with it now, this post should help you out. […]

Leave a Reply