The simplest solution to the dropdownlist input problem in Asp.net

Source: Internet
Author: User

Put this js code in the HTML of your page.

 

Function catch_keydown (SEL) {Switch (event. keycode ){

Case 13: // enter;

Sel. Options [SEL. Length] = New Option ("", "", false, true );

Event. returnvalue = false;

Break;

Case 27: // ESC;

Alert ("text:" + SEL. Options [SEL. selectedindex]. Text + ", value:" + SEL. Options [SEL. selectedindex]. Value + ";");

Event. returnvalue = false;

Break;

Case 46: // Delete;

If (confirm ("exclude content before expiration !? ")){

Sel. Options [SEL. selectedindex] = NULL;

If (SEL. length> 0) {SEL. Options [0]. Selected = true ;}}

Event. returnvalue = false; break;

Case 8: // back space;

VaR S = SEL. Options [SEL. selectedindex]. text;

Sel. Options [SEL. selectedindex]. Text = S. substr (0, S. Length-1 );

Event. returnvalue = false; break ;}}

Function catch_press (SEL ){

Sel. Options [SEL. selectedindex]. Text = SEL. Options [SEL. selectedindex]. Text + String. fromcharcode

(Event. keycode); event. returnvalue = false;

}

Drag a dropdownlist control in your program and find the code of this control on the HTML page.

Add onkeydown = "catch_keydown (this);" onkeypress = "catch_press (this );"

Just run the program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.