je veux Capturer la touche Entrée pour utiliser un bouton cliquez surCapturer la touche Entrée pour utiliser un bouton cliquez avec le javascript
j'ai ce javascript:
function doClick(buttonName,e)
{
//the purpose of this function is to allow the enter key to
//point to the correct button to click.
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
if (key == 13)
{
//Get the button the user wants to have clicked
var btn = document.getElementById('submit');
if (btn != null)
{ //If we find the button click it
btn.click();
event.keyCode = 0
}
}
}
avec html
<input type="button" id="submit" value="Search" onClick="doSomeThing();" />
<input type="text" name="search" onKeyPress="doClick('submit',event)" />
cela fonctionne très bien avec le navigateur IE mais pas avec Firefox,
Pourquoi? Quelqu'un peut-il corriger ce code javascript pour fonctionner sur tous les navigateurs.
merci
Pourriez-vous nous expliquer ce qui se passe? La méthode est-elle appelée du tout? – cwallenpoole
oui du tout. merci – Swell
ce lien vous aidera définitivement http://stackoverflow.com/questions/155188/trigger-a-bouton-cliquez-avec-javascript-sur-le-centre-key-in-a-text-box –