working on a product detail page. i have itemname, itemdescription and itemprice input fields in a single item div.
user can add mutiple item divs dynamically having multiple item input fields.
I have placed the Ids of input fields as Itemname[0]
, itemdesc[0]
, itemprice[0]
in a single item div. and obviously in next divs, it will be Itemname[1]
, itemdesc[1]
, itemprice[1]
and so on.
Problem is that i am not able to fetch the values of these input fields by providing their indexes for example: $('#itemname[0]').val();
gives me undefined
.
How can i achieve this? Thanks so much in advance
#Minimal Reproducible Example:#
<div id="itemset1">
<input type="text" id="itemname[0]" value="Inventory item1">
<input type="text" id="itemdesc[0]" value="Inventory item1 desc">
</div>
<div id="itemset2">
<input type="text" id="itemname[1]" value="Inventory item2">
<input type="text" id="itemdesc[1]" value="Inventory item2 desc">
</div>
How to fetch value of itemname[1]
or itemname[0]
?
console.log($('#itemname[0]').val());
says undefined