Maarten Wolfsen Maarten Wolfsen - 2 months ago 8
Javascript Question

val() function giving console error


has a
attribute, so people can't click higher than the number given. But this doesn't count for typed numbers, they can exceed far beyond the max number given. So, with jQuery, I want to make a solution for this. I already got this:

var productPageInput = $('#product-options-wrapper .option input[type="number"].qty');
var max = 60;
productPageInput.attr('max', max);

productPageInput.bind('keyup input', function(e){
if( $(this).val() > max ){
$(this).val() = max;

But, everytime I execute this code, and I type above 60, this console error appears:

Uncaught ReferenceError: Invalid left-hand side in assignment(…)

Which points to this line:

$(this).val() = max;

What is going wrong here?


To assign a value:


In general, a function call on the left-hand side of an assignment operator in JavaScript doesn't make sense.