Multiple Bootstap touchspon or bootstrap-input-spinner

Viewed 74

I am using the input spinner example from below:

https://shaack.com/projekte/bootstrap-input-spinner/

I need to have multiple spinners for every product. Do I need a separate function for detecting value/change for every instance of the spinner since the function operates on the id of the spinner.

   $inputNet.on("change", function (event) {
       $inputGross.val($inputNet.val() * 1.19)
   })
   $inputGross.on("change", function (event) {
       $inputNet.val($inputGross.val() / 1.19)
   })

Do I need to dynamically generate the JavaScript function as well for every input-select?

1 Answers

You can also use event.target.value or $(event.target).val() to get the value in the callback function.

$inputNet.on("change", function (event) {
    $inputGross.val(event.target.value * 1.19)
})
$inputGross.on("change", function (event) {
    $inputNet.val(event.target.value / 1.19)
})

The bootstrap-input-spinner is programmed in a way that you can use it almost like a native input field. If you read out the value like this you can share the function across multiple spinners.

Related