esc key clears html input text values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coolnags
    New Member
    • Oct 2008
    • 10

    #1

    esc key clears html input text values

    Hi,
    I have created 2 html input text boxes with readonly property set to 'readonly'. I am handling the esc key event(27) in javascript code. When I press the esc key for the first time it will not harm any thing. But if i press the esc key 2nd time it will clear both the input text box values. Please let me know is this the correct behavior? What should I do to retain the text values?

    Thanks,
    Nags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by coolnags
    I am handling the esc key event(27) in javascript code.
    and how do you do that?

    Comment

    • coolnags
      New Member
      • Oct 2008
      • 10

      #3
      I have attached the hadnler using AddHandler api for keydown of the text box whose text is getting cleared. I am using IE6.

      Comment

      • jai00271
        New Member
        • Aug 2012
        • 1

        #4
        IE does this, it is a default behavior, it acts like a form reset button, much the same way that hitting Return does a form submit.

        It does not seem to be a very likely thing for a user to do by accident. There are a TON of hotkeys which can affect your browser, you can not stop all of them: http://www.accessible-devices.com/IE7HotKeys.html

        The only way to retain the values is if they have been assigned in the value="" part when the page is loaded (that is what reset does - resets to the values the fields had when the page loaded). Typically this means hard coding or pre-populating the values on the server side: <input type="text" value="<%=SomeV arible%>">

        P.S.

        I did notice that it seems to only happen if you have set focus to a field. Maybe setting focus to something outside of the form will work for you.

        Comment

        Working...