0

I try to use jQUery-UI autocomplete plugin with a list of inputs that have the same id.

The list is like this:

<input type="text" name="cod[]" id="cod"/>
<input type="text" name="cod[]" id="cod"/>
<input type="text" name="cod[]" id="cod"/>
<input type="text" name="cod[]" id="cod"/>

My script.js function look like this:

$("#cod_prod").autocomplete({
source:getCods
});

Where getCods is a function that load data from a DB with $.ajax method of jQuery.

This work, i try it in other input ... but when i try with this list of multiple input field the plugin only work with the first field.

Any idea of how can i accomplish this?

Thanks in advance

2
  • 2
    id should be unique for each dom element. you can use class instead Commented Oct 21, 2011 at 16:40
  • Based on your question alone, #cod_prod does not exist in the DOM. Please explain to which element cod_prod refers Commented Oct 21, 2011 at 16:41

1 Answer 1

1

ID's need to be unique. Use a class. Since your ID's are not unique, that is why it only works with the first instance of it in the DOM.

<input type="text" name="cod[]" class="cod"/>
<input type="text" name="cod[]" class="cod"/>
<input type="text" name="cod[]" class="cod"/>
<input type="text" name="cod[]" class="cod"/>


$(".cod").autocomplete({
   source:getCods
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.