afdi5
afdi5

Reputation: 337

The input number value on click and on change using control buttons

What event should I use to get an input number value where the value is changed typing or changed with button,

<p><input id="multiplier" type="number"></p>

change doesn't work when types only using the buttons

$('#multiplier').change(function(){
   var value = $(this).val();
});

Upvotes: 2

Views: 1589

Answers (2)

Wimanicesir
Wimanicesir

Reputation: 5121

You can combine two event triggers like this:

$('#multiplier').on('keyup change', function(){
   var value = $(this).val();
   console.log(value)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p><input id="multiplier" type="number"></p>

Upvotes: 1

Mohamed elsayed
Mohamed elsayed

Reputation: 36

 let multiplier = document.getElementById("multiplier");
 
  multiplier.addEventListener("input",function(){
    let value = this.value;
    console.log(value)
  })
<p><input id="multiplier" type="number"></p>

Upvotes: 2

Related Questions