limit textarea characters in javascript


limit textarea characters in javascript:

<style>
.x{
background:lightblue;
font-weight:bold;
font-size:20pt;
padding:0px 10px;
}
.y{
font-family:arial black;
color:red;
}
</style>
<script>
function limitText(v){
    len = v.length;
var s = document.testForm.Msg.value;
c = 10 - len;
    if(len > 10){
    m = s.substr(0,10);
    document.testForm.Msg.value = m;
    c = 0;
    }
    document.testForm.count.value = c;
}
</script>
<form name='testForm'>
<textarea cols='35' rows='6' name='Msg' class='y' onkeyup="javascritp:limitText(this.value);"></textarea>
<input type='button' class='x' name='count' value='10' />
</form>

Demo:

[gickr.com]_3e22cdf6-7032-aea4-f125-dc82db7642c9

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s