Connecting Tech Pros Worldwide Help | Site Map

Need to ignore Enter key in Form

Lars Netzel
Guest
 
Posts: n/a
#1: Nov 19 '05
I really need to stop users from reposting the form with Enter or Return
keys. It bypasses so many onClick validations that nothign works if they use
Enter. I must force the user to CLICK on the "Save" button on my aspx page
and instead totally ignore the Enter Key.

I figured I could use this code

function EnterKeyPress(){ if (window.event.keyCode==13){ alert('No Enter
please'); return false; } }

and call that from
<body onkeydown="javascript:EnterKeyPress();">

But that doesn't work.. sure it triggers but it still makes the page
postback.

OR.. any better solution that I'm not bright enough to think of is welcomed!

please help/
Lars


masoud bayan
Guest
 
Posts: n/a
#2: Nov 19 '05

re: Need to ignore Enter key in Form


try this, in the function:

// cancel the default submit
event.returnValue=false;
event.cancel = true;

masoud


"Lars Netzel" <lars.netzel@NO-SPAM.qlogic.se> wrote in message
news:uX67IDzHFHA.588@TK2MSFTNGP15.phx.gbl...[color=blue]
> I really need to stop users from reposting the form with Enter or Return
> keys. It bypasses so many onClick validations that nothign works if they[/color]
use[color=blue]
> Enter. I must force the user to CLICK on the "Save" button on my aspx page
> and instead totally ignore the Enter Key.
>
> I figured I could use this code
>
> function EnterKeyPress(){ if (window.event.keyCode==13){ alert('No Enter
> please'); return false; } }
>
> and call that from
> <body onkeydown="javascript:EnterKeyPress();">
>
> But that doesn't work.. sure it triggers but it still makes the page
> postback.
>
> OR.. any better solution that I'm not bright enough to think of is[/color]
welcomed![color=blue]
>
> please help/
> Lars
>
>[/color]


Closed Thread


Similar ASP.NET bytes