How to set maxlength for textarea in javascript ?

How to set maxlength for textarea in javascript ?

In this post we will give you information about How to set maxlength for textarea in javascript ?. Hear we will give you detail about How to set maxlength for textarea in javascript ?And how to use it also give you demo for it if it is necessary.

Today, i was planing to post something like regarding to javascript. I was thinking what post should i add and i plan to make maxlength validation with display remaining character count using javascript. So you can simply make character limit with remaining counter in javascript.

Here, i am going to make very simple example to do this, you don’t require to import jquery. You have to just write following javascript code. So I used onkeyup and onkeydown event of code javascript.

It would be easy to use using onkeydown and onkeyup event and make it character count validation in html. So let’s just see bellow example and copy that code. You will get fresh example.

Example:

Also see:How to get max attribute value in jquery?

<!DOCTYPE html>

<html>

<head>

<title>How to set maxlength for textarea in javascript?</title>

</head>

<body>


<div >


<form>

<textarea name="message" placeholder="Write Here..." onkeydown="limitTextOnKeyUpDown(this.form.message,this.form.countdown,160);" onkeyup='limitTextOnKeyUpDown(this.form.message,this.form.countdown,160);'></textarea>

You have

<input readonly type="text" name="countdown" size="3" value="160"> chars are left

</form>


</div>


<script type="text/javascript">

function limitTextOnKeyUpDown(limitField, limitCount, limitNum) {

if (limitField.value.length > limitNum) {

limitField.value = limitField.value.substring(0, limitNum);

} else {

limitCount.value = limitNum - limitField.value.length;

}

}

</script>


</body>

</html>

I hope it can help you….

Hope this code and post will helped you for implement How to set maxlength for textarea in javascript ?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

8  +    =  15

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US