Solved

DropDownList on enter

Posted on 2004-07-31
4
600 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
ID: 11686153
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
ID: 11686209
0
 

Author Comment

by:vinny45
ID: 11686372
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
ID: 11686519
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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