Wednesday, March 3, 2010

How to submit a form on pressing enter key

function clickButton(e, buttonid)
{
var bt = document.getElementById(buttonid);
if (typeof bt == 'object'){
if(navigator.appName.indexOf("Netscape")>(-1)){
if (e.keyCode == 13){
bt.click();
return false;
}
}
if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
{
if (event.keyCode == 13){
bt.click();
return false;
}
}
}
}

//Call this function on last text box of a form with onKeyPress="clickButton(this)"

No comments: