Link to home
Start Free TrialLog in
Avatar of sohrabus
sohrabus

asked on

Enter Key

Hi,
I use following code to prevent enter key:

function noEnter()
{
if (event.keyCode==13)
   event.keyCode=0;
   return false;
}
<Body onkeypress="noEnter();">

The Above Code works fine. it disable enter key to submit form.

Sir,
Is there a any way to exclude a Command button from this?
I mean when Enter Key is Pressed  on a command button, it shoud run.

Kindly give ur feedback.

Rgds,
Sohrab
ASKER CERTIFIED SOLUTION
Avatar of yyyannag
yyyannag

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sohrabus
sohrabus

ASKER

Dear yyyannag,

I'm using ASP.Net server control and don't use HTML control.
pls help me how to do it.

Awaiting ur kind help.

Thanks,
Sohrab
well, I can't really imagine why you can't use the above function, since It's a Javascript function, I asuume it should work on buttons as well. However it had a mistake there. here is the correct code:

function noEnter()
{
      if (event.keyCode==13 && (event.srcElement.tagName != "INPUT" || event.srcElement.type != "button"))
      {
         event.keyCode=0;
         return false;
      }
      else
            return true;
}

I'm not familiar with ASP.NET, so it might not work, but I don't think so...