Enter fires the form submit

I have a div (nice gif dislayed as-if it's a button), on that div is a piece of javascript that handles the ENTER as-if it's a click ($(this).click()). The click does its own thing.

In FireFox, it all works perfectly: the user presses the enter on the button and the click is fired. In IE, the form is submitted not the click()




this is a handy dandy jQuery function i use to get around this.

$(formSelector).find('input, select').keypress(function (event) {

    if (event.keyCode == 13) {

        return false;

formselector is just a variable holding the '#FormId', and buttonSelector is a variable holding the button i want clicked. so in your case it would be: '#IdOfYourDivToClick'.


In IE, the default behavior of the enter key on an input element (button type) is a form submit (most of the time).

You can try to capture the keydown event and check for enter key; if it is then run a event.preventDefault()

Take a look at: https://developer.mozilla.org/en/DOM/event.preventDefault

If you post some code, I can help you by modifying your code. Post your HTML and relevant javascript.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.