?
Solved

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

Posted on 2013-02-01
2
Medium Priority
?
868 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 1500 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

752 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