That way I know that only one of the forms will be sent when the user presses the Enter key and the other will not send at all.
However, if the form that I don't want to be sent is within a form, keyCode does not work. Like this:
The inner calls other PHP code to fetch a value for the "first" text field without actually submitting the outer/main form. That way the user can prefill some of the fields. It all works well but when the user presses the enter key, the inner form will be submitted and the onkeypress="return event.keyCode!=13" code snippet does not work all of a sudden.
How can I fix this? It would also work to set a submit button priority if such even exists, that way, the outer form will be submitted if the user presses the enter button.
To summarize, I want the outer form to be sent when the user presses the enter button, regardless of what field the cursor (or is active) is in and the inner form should never be submitted unless the user clicks on the button.
I have now changed the code so there is only one form and the events are driven based on the name of the submit buttons.
So how do I go about to disable submit on hitting enter on all but one of the buttons? If I use
Code:
onkeypress="return event.keyCode!=13"
in the form tag, none of the buttons will be triggered when the user hits enter.
I have now changed the code so there is only one form and the events are driven based on the name of the submit buttons.
So how do I go about to disable submit on hitting enter on all but one of the buttons?
Do you mean if a submit button is focused, pressing Enter has no effect except on one of them? I think you should show what you have now and the exact operation you want.
If you have a single form, why do you need more than a single submit button?
Two of the submit buttons fetches information from an external source based on a number the user enters in the field next to the button and automatically populates many of the fields in the form. That way the user doesn't need to manually enter this information which in the end saves time and hence enhances productivity.
The problem is that if the user then hits enter once the form is filled out, one of the submit button inside the form get triggered instead of the button that submits the form and therefore re-fetches information and subsequently clears some of the fields the previously filled. That behavior can be changed with some PHP trickery so it's not the end of the world, but I want the form to be submitted without having the user to hit the tab key many times in order to get to the button.
Bottom line is, I don't want the user to ever have to use the mouse which is slower and to many, annoying.
So disabling submission when the enter key is pressed for all but one button would solve all these issues.
Bookmarks