Client side script concepts - Textbox string length

Discussion in 'ASP .Net' started by Pitcairnia, May 28, 2004.

  1. Pitcairnia

    Pitcairnia Guest

    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?
    Pitcairnia, May 28, 2004
    #1
    1. Advertising

  2. <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>
    =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=, May 28, 2004
    #2
    1. Advertising

  3. Pitcairnia

    bruce barker Guest

    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, MCP" <> wrote in message
    news:...
    > <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>
    bruce barker, May 28, 2004
    #3
  4. Sorry one mistake:
    <script language="javascript" for="input" event="onchange">
    {
    var strInput = this.value;
    window.document.all.inputLength.value = strInput.length;
    }
    </script>
    =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=, May 28, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pitcairnia
    Replies:
    0
    Views:
    345
    Pitcairnia
    May 28, 2004
  2. Sam
    Replies:
    3
    Views:
    14,096
    Karl Seguin
    Feb 17, 2005
  3. Magnus Blomberg
    Replies:
    3
    Views:
    718
    Magnus Blomberg
    Apr 14, 2005
  4. Boss302
    Replies:
    0
    Views:
    1,042
    Boss302
    Nov 21, 2006
  5. Trans
    Replies:
    0
    Views:
    155
    Trans
    Apr 23, 2006
Loading...

Share This Page