I am able to create an onlick dynamic button with an incrementer and a decrementer option, but I am unable to create a dynamic id for other buttons due to which these buttons are not getting incremented or decremented. Currently only the first button gets decremented/incremented even when clicked on other buttons.
When you click on +
icon content and a incrementer/decrementer button is added in Manage Portfolio section. I have tried different solutions which have been defined on Stack Overflow but they don't seem to work here.
<table>
<thead>
<tr>
<th>STOCK</th>
<th>PRICE</th>
<th>SHARES</th>
<th>WEIGHT</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="stock in stocksArray" class="portfoliokey">
<td>{{stock.key}}</td>
<td class="portfoliovalue">{{"₹" + stock.value}}</td>
<td>
<input type="button" onclick="decrementValue()" value="-">
<input type="button" id="number" value="0" />
<input type="button" onclick="incrementValue()" value="+" />
</td>
<td></td>
</tr>
</tbody>
</table>
Script
function incrementValue() {
var value = parseInt(document.getElementById('number').value, 10);
value = isNaN(value) ? 0 : value;
value++;
document.getElementById('number').value = value;
}
function decrementValue() {
value = parseInt(document.getElementById('number').value, 10);
value = isNaN(value) ? 0 : value;
value--;
document.getElementById('number').value = value;
}