javascriptjquerydom

jQuery referencing a form object array


This is about form input objects with same names and unknown number of clones/duplicates such as this one:

<input name="field[]" id="field[]" value="">

using jQuery, I dynamically add copies of the object which theoretically makes it look like this:

<input name="field[]" id="field[]" value="">
<input name="field[]" id="field[]" value="">
<input name="field[]" id="field[]" value="">
<input name="field[]" id="field[]" value="">

... and so one and so forth.

How do we reference such objects, say for example, with an on-change procedure?


Solution

  • It is not valid to have multiple elements with the same ID.

    You can get the n-th input using:

    $('input').eq(n)