Selecting the correct input field using jquery

Posted by rshivers on Stack Overflow See other posts from Stack Overflow or by rshivers
Published on 2010-05-21T13:06:24Z Indexed on 2010/05/21 13:10 UTC
Read the original article Hit count: 166

Filed under:
|

I'm trying to select the id's of dynamic input fields in my code. When clicking a button, the form will create a form field like this:

<td><input type="text" id="field_a_1"></td>
<td><input type="text" id="field_b_1"></td>
<td><input type="text" id="field_c_1"></td>

When I click on the button again I get this:

<td><input type="text" id="field_a_2"></td>
<td><input type="text" id="field_b_2"></td>
<td><input type="text" id="field_c_2"></td>

What I want to do is select only the field id that I need to pull the value from that particular input and pass it to a variable like this:

var example = $(":input:eq(0)").val();

I know that by adding the :eq(0) after the :input selector it will only grab the id for field_a_1, so how do I set it up so that I can pull just the field that I need to assign it to a variable?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery