Reputation: 1970
I am trying to run event when the user enters an amount and im getting this error
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
HTML
<input type="text" id="ItemQuantity#i#" name="ItemQuantity#i#" onkeypress="return isNumeric(event)" onkeydown="return keyispressed(event);" onchange="autototal()">
trying to focus on the onchange="autototal()"
JQuery
function autototal(){
var sum = 0;
var quantity = 0;
var price = 0;
var totalPrice = 0;
quantity = $(this).val();
price = $(this).closest('.col-price').find('input').val();
console.log(quantity);
console.log(price);
}
Upvotes: -1
Views: 57
Reputation: 1074148
The way you're calling your handler, this
isn't the element, it's window
.
Either use jQuery to hook up the handler, which will ensure that this
refers to the element:
$("[id='ItemQuantity#i#']").on("change", autototal);
...or if you really want to use onxyz
-attribute-style event handling, either do this:
<input ... onchange="autototal.call(this)">
and it should work as is, or do this:
onchange="autototal(this)"
...and update autototal
to use the argument rather than this
.
Upvotes: 3