I want to capture the Enter key to call a button
I have this javascript:
function doClick(buttonName,e)
{
var key;
if(window.event)
key = window.event.keyCode;
else
key = e.which;
if (key == 13)
{
var btn = document.getElementById('submit');
if (btn != null)
{
btn.click();
event.keyCode = 0
}
}
}
with html
<input type="button" id="submit" value="Search" onClick="doSomeThing();" />
<input type="text" name="search" onKeyPress="doClick('submit',event)" />
this works fine with IE browser, but not with Firefox,
Why? can someone fix this javascript code to work in all browsers.
Thank you
source
share