Solved

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

Posted on 2013-02-01
2
860 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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'…
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…

738 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