Solved

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

Posted on 2013-02-01
2
837 Views
Last Modified: 2013-02-03
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">
0
Comment
Question by:DianaGee
2 Comments
 
LVL 10

Expert Comment

by:Monica P
ID: 38846521
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
0
 
LVL 16

Accepted Solution

by:
Stephan earned 500 total points
ID: 38849271
To have limit on words you can use this: http://jsfiddle.net/4QZy2/2/

<textarea name="description" id="description" onkeypress="return validateText(this);"></textarea>

Open in new window


with the following javascript code:

function validateText (el) {
    var maxWordLength = 10;
    var array = el.value.split(' ');
    if (array.length <= maxWordLength)
    {
        return true;
    }
    return false;
}

Open in new window

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now