Solved

DropDownList on enter

Posted on 2004-07-31
4
597 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

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

Title # Comments Views Activity
IIS URL Rewrite to do 2 actions: Set a ServerVariable, then redirect 3 65
ASP.NET e-commerce website 4 58
Paging GridView 7 49
Not showing page correctly 3 30
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

16 Experts available now in Live!

Get 1:1 Help Now