I have an array of text inputs like this:
<input type="textbox" name="col[]">
<input type="textbox" name="col[]">
<input type="textbox" name="col[]">
They are generated at run time using an "add" button.
I can fetch textbox array values using
$('input[name="col[]"]').each(function(){
alert($(this).val());
});
But if I just need 2nd textbox value then will I fetch it directly without looping through array using jquery?
I appreciate someones help.
I have an array of text inputs like this:
<input type="textbox" name="col[]">
<input type="textbox" name="col[]">
<input type="textbox" name="col[]">
They are generated at run time using an "add" button.
I can fetch textbox array values using
$('input[name="col[]"]').each(function(){
alert($(this).val());
});
But if I just need 2nd textbox value then will I fetch it directly without looping through array using jquery?
I appreciate someones help.
Share Improve this question asked Jan 15, 2013 at 20:22 HiralHiral 1535 silver badges19 bronze badges1 Answer
Reset to default 8Use .eq()
to select it:
var $textboxes = $('input[name="col[]"]')
var value1 = $textboxes.eq(0).val();
var value2 = $textboxes.eq(1).val();
...