Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Enter Key

Posted on 2006-07-10
3
Medium Priority
?
236 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 750 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 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