Solved

Enter Key

Posted on 2006-07-10
3
226 Views
Last Modified: 2010-04-06
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
0
Comment
Question by:sohrabus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
yyyannag earned 250 total points
ID: 17079815
function noEnter()
{
if (event.keyCode==13 && (event.srcElement.tagName != "INPUT" || event.srcElement.type != "button"))
   event.keyCode=0;
   return false;
}

eliminates button elements from running the rest of the code.
0
 

Author Comment

by:sohrabus
ID: 17088076
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
0
 
LVL 2

Expert Comment

by:yyyannag
ID: 17089246
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...
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to count occurrences of each item in an array.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question