What I'm trying to do is make an autocomplete for one of my sites. Autocomplete, on its own, is pretty straight forward, and I got it working with some nice fun features (up/down arrows to move between selections and what not).
It got me thinking, what if I wanted the autocomplete to select between one list if a checkbox wasn't checked, and a different set if it was? How about if I wanted a radio box to alter the selection, or use a second input to filter the results?
So I thought about how I could pass these values into the autocomplete without necessarily knowing what these components would be. I may want to do an autocomplete by game (I'm building an online pen and paper gaming site), so there could be a series of checkboxes to select game types. Or maybe make a system where you can put friends into groups, then search only within that group. There are a lot of possibilities.
Of course, I don't want to repeat the code over and over, with only slight modifications as to the key for a particular value, and the selector to get that value, so I'm trying to figure out how I can pass the data along. I did consider passing the key and the selector, which would allow me to then just run the selector in the function, but I feel like this would be inefficient (I'd need to do a bunch of checks for checkboxes and radio boxes), so I'm hoping to create a JSON and pass it by reference, at this seems to make the most sense. If its not possible, I'll fall back on passing key/selector pairs and then doing the selector within.
I know its not a concrete example of what I want to do, but this is as much a learning experience as anything else... I feel like knowing how to pass information with limited forehand knowledge would be useful.