Country Autocomplete Example with More than one Autocomplete box?

I am trying to create a form where members select their dog’s age and breed. I am trying to follow the Country Autocomplete Example but instead of having the $w() and element ids hardcoded, I want to create a variable that would change depending on which input box is being clicked on. Is this possible?

I have already started working on it, and the only thing I did was create variables and plug them in, but nothing happens. I created variables on the Country Autocomplete sample and it still worked. When I hardcoded the variables into my code it did work, but it did not when the I plugged in the variables.

Any help would be appreciated! Thank you!

Hi!

If you want to avoid duplicating any code you will have to set the current elements. Currently, it looks like your variables only get set once, and then you are not updating them based on which one input is actually being used. You could do this by using the onFocus() event on the text input and then setting your inputs to the appropriate information.

So basically it would look something like this:

export function age1_focus(event) {
    currentDropdown = //your age dropdown element here  
    currentInputBox = //your age inputBox element here
}

And then the same for the other elements and the breed input.

Hope this helps!