I'm working on a price calculator and want to calculate the price depending on the button selected. I'm also looking for a way to do this with only one function instead of having onclick function for every single button.
I have tried creating an onclick event for every single button, but that was not the way to go as the document was full of pointless functions.
<div class="btn-toolbar mb-3" role="toolbar">
<div class="btn-group btn-group-sm" role="group" style="margin: auto;">
<span class="input-group-text" id="inputGroup-sizing-sm">Počet vodivých vrstev</span>
<button type="button" class="btn btn-secondary btn-form">1</button>
<button type="button" class="btn btn-secondary btn-form">2</button>
<button type="button" class="btn btn-secondary btn-form">4</button>
<button type="button" class="btn btn-secondary btn-form">6</button>
</div>
</div>
I expect to use only one function for all these buttons and only read the button value and work with it afterwards. I have been using onclick for every single button so far, but it was not the way to go, because the document ended up being full of functions containing only one line which I think is possible with only one function, instead of having a huge amount of functions and click events. I also expect the button to change the total product price contained in a variable named $currentPrice, which I am updating on change and click events, so it only has to edit the variable $currentPrice.