Client side script concepts - Textbox string length

P

Pitcairnia

I have as an example this very simple page

<html>
<head>
</head>
<body>
<form id="myForm" runat="server">
<asp:textbox id="input" runat="server" />
<br>
<asp:label id="inputLength" runat="server" />
</form>
</body>
</html>

I want the label to reflect the length of the string being typed in
the textbox and update on every keystroke. Any ideas?
 
G

Guest

<html><head><script language="javascript" for="input" event="onchange"

var strInput = this.value
window.document.all.inputLength = strInput.length

</script></head><body><form id="myForm" runat="server"><asp:textbox id="input" runat="server" /><br><asp:label id="inputLength" runat="server" /></form></body></html>
 
B

bruce barker

besides not working (onchange will not fire until focus leaves the field)
its pretty non w3c compliant code, try:

<html>
<head>
<script language="javascript">
function displayLength(e) {
document.getElementById('inputLength').innerHTML =
e.value.length;
}
</script>
</head>
<body>
<form id="myForm" runat="server">
<asp:textbox id="input" runat="server"
onkeyup="displayLength(this)" /><br>
<asp:label id="inputLength" runat="server" />
</form>
</body>
</html>

Bin Song said:
<html><head><script language="javascript" for="input" event="onchange">
{
var strInput = this.value;
window.document.all.inputLength = strInput.length;
}
</script></head><body><form id="myForm" runat="server"><asp:textbox
id="input" runat="server" /><br><asp:label id="inputLength" runat="server"
/></form></body></html>
 
G

Guest

Sorry one mistake:
<script language="javascript" for="input" event="onchange">
{
var strInput = this.value;
window.document.all.inputLength.value = strInput.length;
}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top