Solved

DropDownList on enter

Posted on 2004-07-31
4
596 Views
Last Modified: 2006-11-17
When I type a letter on a dropdownlist it would scroll down to the first word of the letter, how do I add the functionality to submit the form when I press enter while having focus on the dropdownlist. Basically adding an event handler that would trigger an onEnter event on a dropdownlist.


0
Comment
Question by:vinny45
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Joeisanerd
Comment Utility
Just add an onkeydown javascript like this

<html>
<head>
      <script language="Javascript">
      function CheckForEnterKey()
      {
         if( event.keyCode == 13 )
         {
            document.forms[0].submit();
         }
      }      
      </script>
</head>
      <body>
            <form id="form1" action="http://www.google.com" method="post">
                  <select id="myDDL" onkeydown="CheckForEnterKey()">
                        <option value="1">Abc</option>
                        <option value="2">BAbc</option>
                        <option value="3">BBAbc</option>
                        <option value="4">Cabc</option>
                  </select>
            </form>
      </body>
</html>

keyCode is 13 for the enter key.
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
0
 

Author Comment

by:vinny45
Comment Utility
oh i'm sorry, I'm meant asp.net dropdownlist control, Aesros, will you're ariticle still work with web controls?
0
 
LVL 9

Accepted Solution

by:
Joeisanerd earned 500 total points
Comment Utility
The code I posted was just to show you the Javascript, you can register the javascript functon in you asp.net code. If you put it in the page_load code you could write

string strFunction = "<script language="Javascript"> function CheckForEnterKey() {  if( event.keyCode == 13 ) ";
strFunction +=" {   document.forms[0].submit(); } }  </script>";

RegisterStartupScript("EnterKeyFunction", strFunction);

then in the html section you would and the onkeydown="CheckForEnterKey()" code or if you are doing strictly in C# code then after the RegisterStartupScript function above you could call the AddAttribute method of the control

ddl.AddAttribute("onkeydown", "CheckForEnterKey()");

that should work.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

11 Experts available now in Live!

Get 1:1 Help Now