I am currently developing a plugin for wordpress, and using jquery autocomplete. In my plugin file i enque autocomplete like this:


Then i assign the script to an input id like this:


This works fine for one input. However i am using repeatable / reuasble input fields (they can be created on the fly). They all have the same id of #post_email_repeatable.

Auto-complete will only work on the first input with the id of #post_email_repeatable.

My question is, is it possible to get auto-complete to work on work than one input with the same id?

  • 3
    ID's must be unique, this is not specific to WordPress. Use a class.
    – Milo
    Jan 3 '14 at 15:18

Auto complete is most likely not working on the extra fields because they are added with javascript dynamically, and when you make your javascript .autocomplete() call, it runs on page load. Your dynamically created fields do not exist yet to have autocomplete hooked with them. Try this.

jQuery(document).on("keydown", ".post_email_repeatable", function(){
        source: "get_posts.php",
        minLength: 1

This binds the autocomplete function the input field with that class whenever the keydown event happens on it. So it will trigger even when keydown event happens on newly dynamically created fields.

Also as Milo commented, you should use a class as ID's should be unique, however not having unique IDs shouldnt break the functionality of it. I still suggest you add a "post_email_repeatable" class to each repeatable field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.