Skip to content Skip to sidebar Skip to footer

How Do I Handle Number Input Changes In Jquery?

I'm trying to create a checkout menu with jQuery and HTML and I am having trouble getting the input box for the item quantity to behave predictably. When I use the cursor to change

Solution 1:

There are only a few changes required to make your code work. Be aware that you still need to handle negative numbers (by field properties?) as well as 0.

$(document).ready(function() {
    // grep the price only once...var price = parseFloat($("#total").text());        
    functionupdatePrice() {        
        var sum, num = parseInt($(this).val(),10);
        // if we have a numberif(num) {
          // update info text
          sum = num * price;
          $("#total").text(sum.toFixed(2));
        }
    }
    $(document).on("change, mouseup, keyup", "#quantity", updatePrice);
});

Fiddle is here.

Post a Comment for "How Do I Handle Number Input Changes In Jquery?"