function wordCounter(field, countfield, maxlimit) {
wordcounter = 0;
for (x = 0; x < field.value.length; x++) {
if (field.value.charAt(x) == " " && field.value.charAt(x - 1) != " ") { wordcounter++ } // Counts the spaces while ignoring double spaces, usually one in between each word.
According to your question, i thought that you required such type of solution in which "When typing the words in textbox, the word count displaging in counter label, whenever counter label show 0, user dont allow to type there after... "....if there is something
wrong with your question then plz edit it and elaborate more within your requirements..
riyaju
Member
44 Points
118 Posts
How Dont allow to type when exceed maximum words?
Jul 24, 2012 03:10 AM|LINK
Script
<SCRIPT language="JavaScript" type="text/javascript">
function wordCounter(field, countfield, maxlimit) {
wordcounter = 0;
for (x = 0; x < field.value.length; x++) {
if (field.value.charAt(x) == " " && field.value.charAt(x - 1) != " ") { wordcounter++ } // Counts the spaces while ignoring double spaces, usually one in between each word.
if (wordcounter > 100) { field.value = field.value.substring(0, x); }
else {
countfield.value = maxlimit - wordcounter;
}
}
}
</script>
ASPX:
<asp:TextBox ID="txtAnswerforQuestion11" runat="server" TextMode="MultiLine" Columns="40" Rows="6" onKeyDown="wordCounter(this,this.form.remLentext,100);" onKeyUp="wordCounter(this,this.form.remLentext,100);"></asp:TextBox>
Words remaining:<input type="box" readonly name="remLentext" size="3" value="100">
How can Dont allow to type when exceed maximum words size showing in words counter box like '0', user can type with in limit '100' allow backspace.?
javascpt
Usman Amir
Participant
790 Points
138 Posts
Re: How Dont allow to type when exceed maximum words?
Jul 24, 2012 03:27 AM|LINK
use this script
<script type="text/javascript"> function wordCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit) { field.value = field.value.substring(0, maxlimit); } else { countfield.value = maxlimit - field.value.length; } } </script>i dnt understand what you are talking about spaces & backspaces?will you elaborate more...
riyaju
Member
44 Points
118 Posts
Re: How Dont allow to type when exceed maximum words?
Jul 24, 2012 03:38 AM|LINK
When typing the words in textbox, the word count displaging in counter label, whenever counter label show 0, user dont allow to type there after...
Usman Amir
Participant
790 Points
138 Posts
Re: How Dont allow to type when exceed maximum words?
Jul 24, 2012 03:58 AM|LINK
According to your question, i thought that you required such type of solution in which "When typing the words in textbox, the word count displaging in counter label, whenever counter label show 0, user dont allow to type there after... "....if there is something wrong with your question then plz edit it and elaborate more within your requirements..
riyaju
Member
44 Points
118 Posts
Re: How Dont allow to type when exceed maximum words?
Jul 24, 2012 04:25 AM|LINK
ok
The Textbox must allowed within 100 words,
when the textbox only exist the limit 100, you dont allow to type the user.
Words count displaying beside of textbox label
Usman Amir
Participant
790 Points
138 Posts
Re: How Dont allow to type when exceed maximum words?
Jul 24, 2012 04:35 AM|LINK
ok your aspx code will look like as
and your javascript goes as
<script type="text/javascript"> function wordCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit) { field.value = field.value.substring(0, maxlimit); } else { countfield.value = 0 + field.value.length; } } </script>kirupa.v
Contributor
2070 Points
531 Posts
Re: How Dont allow to type when exceed maximum words?
Jul 24, 2012 04:38 AM|LINK
Hi,
Try the following code
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Limit Characters in a Multiline TextBox</title>
<script type='text/javascript'
src='http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js'>
</script>
<script type="text/javascript">
$(function() {
var limit = 100;
$('textarea[id$=tb1]').keyup(function() {
var len = $(this).val().length;
if (len > limit) {
this.value = this.value.substring(0, limit);
}
$('#spn).text(limit - len + " characters left");
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="tb1" runat="server" TextMode="MultiLine"/><br />
<span id="spn "></span>
</div>
</form>
</body>
</html>
Reply me for any issues..
riyaju
Member
44 Points
118 Posts
Re: How Dont allow to type when exceed maximum words?
Jul 24, 2012 04:59 AM|LINK
Thanks,
script working...
I can type after cross 100 words, but text box must allowed 100 words only...
Dont give permission to user to type further cross 100 words... but can edit words with in 100 words
[Note : only count depends on words, not character]
raju dasa
Star
14412 Points
2452 Posts
Re: How Dont allow to type when exceed maximum words?
Jul 24, 2012 07:22 AM|LINK
Hi,
check this link, (code, preview available):
http://jsbin.com/unozeq/4/edit
modify it for ur purpose and requirement.
javascpt
rajudasa.blogspot.com || blog@opera
riyaju
Member
44 Points
118 Posts
Re: How Dont allow to type when exceed maximum words?
Jul 25, 2012 03:33 AM|LINK
http://jsbin.com/unozeq/4/edit
Error 503 Service Unavailable