El botón Enter no actúa como el botón clic en MVC2

I have an MVC2 project that has a page on it that is supposed to call a jquery function. When you click on the button via the mouse my jquery function is called. I of course have a .click() function call on my button ID. My guess is that I am simply performing a form submit when I press enter instead of going through the click motion. Is there a way that I can either have the enter button do the same thing as the .click() or at least use jquery or anything as a matter of fact to disable the enter button so that a user can not hit enter and will have to press via the mouse?

Any ideas will be greatly appreciated. In the meantime, I will continue to scour the internet to figure out what I can do for this.

Gracias.

preguntado el 08 de noviembre de 11 a las 11:11

2 Respuestas

Prueba esta

$("#frmEdit").keypress(function (event) {

    if (event.which == 13 && event.target.nodeName != "TEXTAREA") {
        $('#btnSubmit').click();
        event.preventDefault();
    }

});

This function looks for enter key press for all controls except TextArea and calls a submit event.

respondido 08 nov., 11:16

I would think that you should be able to just hook into the forms enviar evento:

$('#myForm').submit(function() {
...
});

Using this should handle either the button click or an enter key press.

Respondido el 01 de enero de 14 a las 22:01

I would think so to. But for some reason, It wasn't taking. - SoftwareSavant

just took a look at my code again... I was attempting to use .submit on the button id and not the form ID? Let me try on the form id and see what happens. - SoftwareSavant

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.