i am suing a function in which i try to limit textarea length but on one condition i am getting the above mentioned error. Please tell me what i am doing wrong?
function limitTextArea(element, limit) {
var $textArea = $(element);
($textArea).keypress(function(event){
if ($textArea.val().length == limit) {
event.preventDefault();
} else if ($textArea.val().length > limit) {
// Maximum exceeded
$textArea.val() = $textArea.val().substr(0, limit);
}
}); //end of keypress
} //end of function()
The line
$textArea.val() = $textArea.val().substr(0, limit);
give me error that invalid assignment left-hand side. Why i am getting that?
Thanks
$textArea.val()is a function so you don’t want to assign a string to it.The following code will assign the value to $textArea: