javascript - Prevent Addition input -


i want stop taking input in text field once 10 characters have been entered.

what have far not working:

$(document).ready(function() {   $('#comment').keypress(function(event){      if ($('#comment').val()).length == 10) {         event.preventdefault();     }    }); }); 

what missing?

you don't need jquery this. use maxlength attribute instead. can used input or textarea elements:

<input id="comment" maxlength="2" type="text"> <textarea maxlength="100"></textarea> 

Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -