Solved

Enter Key

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

708 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

18 Experts available now in Live!

Get 1:1 Help Now