By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,028 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,028 IT Pros & Developers. It's quick & easy.

ASP.Net Running total of Character Count on input

P: n/a
BJ
Ever see those nifty sites that allow you to type text into a single or
multi line text box and decrement from the maximum number of characters
to 0?

This lets the user know they are approaching the maximum length to the
textbox. Does anyone have any examples of this script? It is for an
ASP.Net page that has some client side java script.

TIA

BJ

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Try this (in VB script)...
TextBox1 is the textbox you are monitoring, TextBox2 is a textbox you are
displaying the current count in.

<script language="vbscript">
maxLength = 500
Private sub mytextbox_onkeypress ()
document.all.TextBox2.value = maxLength - len(document.all.TextBox1.value)
end sub
</script>

be sure to add the following to your textbox (client side)
onkeyup="mytextbox_onkeypress"

"BJ" <ju**********@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Ever see those nifty sites that allow you to type text into a single or
multi line text box and decrement from the maximum number of characters
to 0?

This lets the user know they are approaching the maximum length to the
textbox. Does anyone have any examples of this script? It is for an
ASP.Net page that has some client side java script.

TIA

BJ

Nov 21 '05 #2

P: n/a
BJ
Jim,

Thanks for the response. That didn't work but I do not think it is the
code.
Error:
Line 146
Char: 1
Error: 'mytextbox_onkeypress' is undefined
code: 0
URL:http://localhost/chem/Default.aspx
My page is an ASP.Net page (called Defalut.aspx) that hosts a user
control that contains input fields. So on the HTML of the contorl I
coded the following:

<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="UnauthorizeChem.ascx.vb" Inherits="Chem.UnauthorizeChem"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<h1 style="FONT-FAMILY: Verdana">UnAuthorize a Chemical Product
Application</h1>

<input id="textbox2" onkeyup="mytextbox_onkeypress" />
<BR>
<script language="vbscript">
maxLength = 500
Private sub mytextbox_onkeypress()
document.all.TextBox1.value = maxLength -
len(document.all.textbox2.value)
end sub
</script>
<BR>
<BR>
<BR>
<BR>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>

I tried to place the script in the head section of the Default.aspx
page but that only locked up my page.

Nov 21 '05 #3

P: n/a
I'm not sure, but try removing the / at the end of your text box
definition...
<input id="textbox2" onkeyup="mytextbox_onkeypress">

here is what I had...

<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="vbscript">
maxLength = 500
Private sub mytextbox_onkeypress ()
document.all.TextBox2.value = maxLength - len(document.all.TextBox1.value)
end sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<input type="text" id="TextBox1" size="80"
onkeyup="mytextbox_onkeypress">
<input type="text" id="TextBox2" >
</form>
</body>
</HTML>

"BJ" <ju**********@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Jim,

Thanks for the response. That didn't work but I do not think it is the
code.
Error:
Line 146
Char: 1
Error: 'mytextbox_onkeypress' is undefined
code: 0
URL:http://localhost/chem/Default.aspx
My page is an ASP.Net page (called Defalut.aspx) that hosts a user
control that contains input fields. So on the HTML of the contorl I
coded the following:

<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="UnauthorizeChem.ascx.vb" Inherits="Chem.UnauthorizeChem"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<h1 style="FONT-FAMILY: Verdana">UnAuthorize a Chemical Product
Application</h1>

<input id="textbox2" onkeyup="mytextbox_onkeypress" />
<BR>
<script language="vbscript">
maxLength = 500
Private sub mytextbox_onkeypress()
document.all.TextBox1.value = maxLength -
len(document.all.textbox2.value)
end sub
</script>
<BR>
<BR>
<BR>
<BR>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>

I tried to place the script in the head section of the Default.aspx
page but that only locked up my page.

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.