How to retrieve the dropdownlist and radiobuttonlist control values in Javascript

Source: Internet
Author: User

1. Get the dropdownlist Control Value

Function getdllvalue (ID ){
VaR r = Document. getelementbyid (ID );
For (VAR I = 0; I <R. length; I ++ ){
If (R [I]. Selected ){
Return R [I]. text;
}
}
}

PS: ID is the Control ID, which must be enclosed by quotation marks.

VaR text = getdllvalue ("ddlcustomerlevel ");

2. Obtain the radiobuttonlist control value.

// Obtain the value of the selected item

Function selectradiobuttonlistvalue (ID ){
VaR r = Document. getelementbyid (ID );
VaR P = R. getelementsbytagname ("input ");
For (VAR I = 0; I <p. length; I ++ ){
If (P [I]. Checked ){
Return P [I]. value;
}
}
}

// Convert the radiobuttonlist control to enumerate Chinese values based on the obtained value
Function getrbltext (RVA ){
Switch (RVA ){
Case 0:
Return "already ";
Break
Case 1:
Return "not ";
Break
Default:
Return "not ";
}
}

PS: ID is the Control ID, which must be enclosed by quotation marks.

VaR text = getrblnettypetext (selectradiobuttonlistvalue ("rblnettype "));

3. The dropdownlist control appears in ASP. NET. After the value is selected, it is restored to the first default by default. There are two reasons for this situation:

First: No ispostback judgment

Type 2: When datasource values are assigned, the corresponding datavaluefield has repeated values.

 

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.