Solved

DropDownList on enter

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

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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