Trying to get the values of all inputs inside a div. The inputs are options with a product.
The product div ID is like this:
<div class="row border" id="p-$productID">
Each unique input id in the (product) list is generated like this:
p-$productID-$otherkeyThatIsNeverTheSame
We get $productID from the data-name value of the button clicked.
Below I am trying to find a way how @RomainGuidoux explains it here: jQuery Selector: Id Ends With?.
Just can't seem to make this work.
$('.btn#add_item').on('click', function () {
var prod = $(this).attr('data-name');
var allVal = '';
$("[id^='p-'+prod+'] > input").each(function() {
allVal += '&' + $(this).attr('name') + '=' + $(this).val();
});
alert(allVal);
});
The iteration is like this:
<select class="form-control" id="p-1-1" name="A">
<option>Type broodje</option>
<option value="Witte pistolette">Witte pistolette</option>
<option value="Bruine pistolette">Bruine pistolette</option>
</select>
<select class="form-control" id="p-1-2" name="B">
<option>Boter</option>
<option value="Met boter">Met boter</option>
<option value="Zonder boter">Zonder boter</option>
</select>
<select class="form-control" id="p-1-3" name="C">
<option>beleg</option>
<option value="Standaard belegd">Standaard belegd </option>
<option value="Dubbel Belegd">Dubbel Belegd</option>
</select>