Results 1 to 2 of 2

Thread: [RESOLVED] asp:textbox need realtime textchange

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Resolved [RESOLVED] asp:textbox need realtime textchange

    I've designed a GUI where I want to enable a button depending on the contents of an asp:textbox.
    If the textbox is empty, the button should be disabled, and if there is text in the textbox, the button should be enabled.

    I've tried using the code behind textbox textchanged event, which works, but it only works after the textbox loses focus.
    I've tried hooking up onKeyDown...

    Code:
    t1.Attributes.Add("onkeydown", "return handleKeyDown(t1, a1)")
    Where t1 is the textbox, and a1 is the button to enable/disable.
    The javascript...

    Code:
    function handleKeyDown(textbox, button) 
    { 
      button.disabled = (textbox.value.trim == "" || textbox.value == null);
      return true;
    }
    The javascript method works great for adding text, but when using backspace or delete, the enable/disable code doesn't work if the textbox is empty...

    Any pointers here?

  2. #2

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: asp:textbox need realtime textchange

    ***resolved

    Code:
    function handleKeyUp(textbox, button) 
    { 
      if(textbox.value) {
        button.disabled = false;         
      }
      else {
        button.disabled = true;         
      } 
      return true;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width