Solved

Enter Key

Posted on 2006-07-10
3
207 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now