Maarten Wolfsen Maarten Wolfsen - 1 year ago 80
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?

Answer Source

To assign a value:


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download