button focus and pressing enter

  • Thread starter Thread starter Philip Townsend
  • Start date Start date
P

Philip Townsend

Can anybody tell me how I can disable the enter (keyboard) button from
being able to submit a form? In other words, force the user to click a
button with the mouse?
 
Heres a simple way, not the best way maybe.

<script language="javascript">
function keyPress()
{
if (event.keyCode == 13)
{
event.returnValue = false;
}
}
</script>


<body onkeypress="KeyPress();">
or you can specify each textbox, etc.. by placing code like this in the
Page_Load Event
this.tbCode.Attributes.Add("onkeypress", "keyPress();");

the same technique can be used to fire an event like save, or search
function keyPress()
{
if (event.keyCode == 13)
{
event.returnValue = false;
document.getElementById("btnDoSearch").click();
}
}

Karl
 
Back
Top