Link to home
Start Free TrialLog in
Avatar of DianaGee
DianaGee

asked on

ext.net - TextArea limit word in textarea to 10 - max words

Ext.net ver 2.0

I have a 5 textareas defined and I want to the stop the user from entering more that 10 words in each textarea. Should I be using listners and what js code should I implement. I am weak in Js. Thanks for your help.
 
<ext:TextArea id="id1" runat="server" enableKeyEvents="true">
<ext:TextArea id="id2" runat="server" enableKeyEvents="true">
<ext:TextArea id="id3" runat="server" enableKeyEvents="true">
<ext:TextArea id="id4" runat="server" enableKeyEvents="true">
<ext:TextArea id="id5" runat="server" enableKeyEvents="true">
Avatar of Monica P
Monica P
Flag of India image

The onchange will prevent context-menu pasting, and the onkeyup will fire for every keystroke


for example

<script type="text/javascript">
function change (el) {
var max_len = 10;
if (el.value.length > max_len) {
el.value = el.value.substr(0, max_len);
}
document.getElementById('char_cnt').innerHTML = el.value.length;
document.getElementById('chars_left').innerHTML = max_len - el.value.length;
return true;
}
</script>

Open in new window


<form>
<textarea cols=100 rows=20 onkeyup="change(this);"></textarea>
<br>You've typed <span id="char_cnt">0</span> character(s). You
are allowed <span id="chars_left">lots</span> more.
</form>

Open in new window


to check it for more

http://snipplr.com/view/13601/
http://stackoverflow.com/questions/1125482/how-to-impose-maxlength-on-textarea-in-html-using-javascript/1125521#1125521
ASKER CERTIFIED SOLUTION
Avatar of Stephan
Stephan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial