How to take value from input type number ? JavaScript

Hi I whana take value with javascript from input type number field. I whana take value always then new number is select, bescause in other field I whana calculate how much it gone cost.

<td>
    <input type="number" id="kiek1000classico" name="kiek1000classico" min="1" max="99">
</td>
<td>
    <script>
        var kiek = document.getElementById("kiek1000classico").value;
    </script>
</td>

Now it always return empty string, I just need know how take number every time then it changed without refresh page. I am using wordpress

Related posts

Leave a Reply

3 comments

  1. try this

    you have to wire the onchange event of the text box.

    For Pure Javascript

    <input type="number" onchange="checkTextbox(this)" id="kiek1000classico" name="kiek1000classico" min="1" max="99">
    
    <script>
    function checkTextbox(element){
        var kiek = element.value;
        alert(kiek);
    }
    </script>
    

    With Jquery it will be more simple

    <script>
    
    $(function(){
            $('#kiek1000classico').on('change',function(){
                  alert($(this).val());
            });
        })
    
    </script>
    
  2. Try This one

          $(document).ready(function () {
              $('#kiek1000classico').change(function () {
                  var data = $('#kiek1000classico').val();
                  alert(data);
              });
          });
    
  3. Better to use jquery in wordpress

    $(document).ready(function(){
     $('#kiek1000classico').change(function(){
      var kiek = parseInt($(this).val());
      alert(kiek);
     });
    });
    

    This is was for “change” event, you can also use “blur” event in the same manner.