views:

295

answers:

2

Hi Folks,

I have a scenario in which I have 2 Submit Buttons in a form for going back and forward.

Both the buttons have different JavaScript associated with it. It is working great if we press these buttons to navigate.

But when in Google Chrome, when someone press enter on any of the text box within the Form it does not calls the onClick of the button.

Is there any work around for that.

Thanks

A: 

You'll need to hook the keypress event and look for key code 13, unfortunately. Not all browsers (in fact, virtually none I think) will trigger the click event on a submit button if you didn't actually click the button. They will trigger the submit event on the form.

So the pattern becomes: Put the validation (et. al.) you want to run when they click the default submit button in a function, and call that function from the keypress event if the key code is 13 and there are no modifier keys down, and from the click of that button.

When dealing with keyboard events, I find this page invaluable.

T.J. Crowder
A: 

alternatively, you can use the onsubmit to do what you wanted to with the onclick of the submit.

sounds like you want to simply have this return false so that nothing happens, and they must use one of your buttons.

contagious