<html><head>
<title>(Type a title for your page here)</title>
<script language=JavaScript>
<!--
function check_length(my_form)
{
maxLen = 50; // max number of characters allowed
if (my_form.my_text.value.length >= maxLen) {
// Alert message if maximum limit is reached.
// If required Alert can be removed.
var msg = "You have reached your maximum limit of characters allowed";
alert(msg);
// Reached the Maximum length so trim the textarea
my_form.my_text.value = my_form.my_text.value.substring(0, maxLen);
}
else{ // Maximum length not reached so update the value of my_text counter
my_form.text_num.value = maxLen - my_form.my_text.value.length;
}
}
//-->
</script>
</head>
<body>
<form name=my_form method=post>
<textarea onKeyPress=check_length(this.form); onKeyDown=check_length(this.form);
name=my_text rows=4 cols=30></textarea>
<br>
<input size=1 value=50 name=text_num> Characters Left
</form>
</body>
</html>
| duna | 30-05-2012 |
| thank you, this worked well for me. | |
| shana | 10-07-2012 |
| its very useful to all | |
| Peter | 19-07-2012 |
| Thanks, u helped me so much :) | |
| Cristian | 04-10-2012 |
| thanks a lot for the code! | |
| Ram | 23-04-2013 |
| Damn Good Code | |
| Raman | 23-04-2013 |
| The code was right but need for button disabling with alert too | |
| 589 | 30-06-2014 |
| good | |
| Manoj Kumar | 23-07-2014 |
| Thnks sir, for best way of your code | |
| srilakshmi | 19-12-2014 |
| great job this is simple user understandable code,nd this helps me thanqx. | |
| srilakshmi | 19-12-2014 |
| Damn good job | |
| madhu | 03-08-2015 |
| You code is very usefull ...Thanks | |
| Akshit Saxena | 25-08-2015 |
| what if we press the "Backspace"... the code crashes in word count in that case... cannot be applied to major project.. can you please help it out...?? | |
| Aravind | 30-04-2016 |
| useful to beginner | |