locked
Unexpected Enter key capture

    Question

  • I have an html  page with the following code snippet:

    <table>
    
    <td><tr><button id="BackButton" >Back</button></tr></td>
    
    <td><tr><fieldset><input id="UserInput"></input></fieldset></tr></td>
    
    </table>

    Now the page is supposed to do an action when the input element is changed, and it does so long as the Enter key is not pressed. When the enter Key is pressed the back button's onclick event is activated. How can I prevent the the back button from capturing the Enter key in the input element?

    Friday, August 17, 2012 7:23 PM

Answers

  • There must be more to your code than this.  If you paste this into a blank app, the BackButton onclick handler is not called.


    Jeff Sanders (MSFT)

    Friday, August 17, 2012 8:40 PM
    Moderator
  • Hi,

    As pointed out by Jeff, this is not the default behavior. Check if you have some code that may cause the behavior. For example, you may have set the button as the default button of a form.

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework

    • Marked as answer by Dino He Monday, September 24, 2012 2:52 AM
    Wednesday, August 29, 2012 3:20 PM
    Moderator

All replies

  • There must be more to your code than this.  If you paste this into a blank app, the BackButton onclick handler is not called.


    Jeff Sanders (MSFT)

    Friday, August 17, 2012 8:40 PM
    Moderator
  • Hi,

    As pointed out by Jeff, this is not the default behavior. Check if you have some code that may cause the behavior. For example, you may have set the button as the default button of a form.

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework

    • Marked as answer by Dino He Monday, September 24, 2012 2:52 AM
    Wednesday, August 29, 2012 3:20 PM
    Moderator