Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
OnKeyPress on Input
Message
De
12/03/2012 08:42:30
 
 
À
Tous
Information générale
Forum:
Javascript
Catégorie:
Autre
Titre:
OnKeyPress on Input
Divers
Thread ID:
01538034
Message ID:
01538034
Vues:
99
By default, if you have an input field with a Input Type=Submit button, this will make it a post if you hit Enter in an input field of the form. This works ok for as long as the submission control is as indicated. However, if you have a graphical toolbar for the Save/Cancel, for example, in order to simulate the same, we have to use the OnKeyPress event of an input field and assign a javascript function which will determine if the Enter key was press so to submit the form.

Instead of adding this OnKeyPress event to every input field, would there be a way to have it generic? I can assign document.onkeypress=FormKeyPress, which will be the javascript function. But, this will also trigger a call to this function whenever an Enter key is pressed, even if this is in a textarea field. In that case, it should not post the form. So, based on that approach, the one which adds an event at the form level, is there a way to detect that the click was done in an input field or a textarea field so to avoid doing anything if the click was done in a textarea field?

Note that onkeypress is recommanded to be replaced by onkeydown so it will work with all browsers as some of them intercept the ESC key, such as Chrome, and they will not hit the event.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform