Reputation: 349
<input type="text" name="fruits[]" value="Apple">
<input type="text" name="fruits[]" value="Banana">
<input type="text" name="fruits[]" value="Orange">
My question is how to change the value of "Orange" to "Grapes" using jquery? The below code is not working.
<script>
$("input[name='fruits[2]']").val("Grapes");
</script>
Thanks in advance.
Upvotes: 0
Views: 118
Reputation: 388316
input[name='fruits[2]']
looks for input elements with name fruits[2]
instead of with name fruits[]
and is at the 3rd indexSo
jQuery(function () {
$("input[name='fruits[]']:eq(2)").val("Grapes");
})
Demo: Fiddle
Upvotes: 1