[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Character Counter for Multiline Textbox

Posted on 2004-10-06
2
Medium Priority
?
896 Views
Last Modified: 2013-12-03
Does anyone know how to modify the javascript below in order for this character counter to work with a multiline textbox rather than a textarea?

This is the control I want to use:

***************
<asp:TextBox id="Description2" runat="server" Height="136px" Width="352px" TextMode="MultiLine"
                  MaxLength="255"></asp:TextBox>
***************

This is the script and html that is working:

***************

<script language="Javascript">

function taLimit() {
      var taObj=event.srcElement;
      if (taObj.value.length==taObj.maxLength*1) return false;
}

function taCount(visCnt) {
      var taObj=event.srcElement;
      if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
      if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
</script>

<form id="Form1" method="post" runat="server">
         <table>
      <tr>
            <td>
                            <font>Maximum Number of characters for this text box is 255.<br>
                                     <TEXTAREA runat="server" onkeypress="return taLimit()" onkeyup="return taCount                     (myCounter)"  name="Description" rows="7" wrap="physical" cols="40" maxLength="255"></TEXTAREA>
<br>
                        You have <B><SPAN id="myCounter">255</SPAN></B> characters remaining for your description...</font>
                     </td>
              </tr>
 </table>
</form>

***************
0
Comment
Question by:Gezna
[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 29

Accepted Solution

by:
David H.H.Lee earned 2000 total points
ID: 12238493
Gezna ,
For your information, the MaxLength property has no effect in a multi-line textbox. This property only work at SingleLine/Password Mode.
However, you can make this modification to adapt with your existing code :

code-behind
--------------------------
   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Description2.Attributes.Add("onkeypress", "javascript:return taLimit2('" & Description2.MaxLength & "');")
        Description2.Attributes.Add("onkeyup", "javascript:return taCount2(myCounter,'" & Description2.MaxLength & "');")
    End Sub

javascript
-------------------------
function taLimit2(maxValue) {
     var taObj=event.srcElement;
     if (taObj.value.length==maxValue*1) return false;
}

function taCount2(visCnt,maxValue) {
     var taObj=event.srcElement;
     if (taObj.value.length>maxValue*1) taObj.value=taObj.value.substring(0,maxValue*1);
     if (visCnt) visCnt.innerText=maxValue-taObj.value.length;
}

or
You can check this link if you interest :
http://www.codeproject.com/aspnet/textlengthvalidator.asp

Regards
x_com
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12238542
Hi,

just an addition, the multiline asp:textbox control is rendered as textarea in html

Regards,
B..M
0

Featured Post

Independent Software Vendors: 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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

649 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