Javascript operation dropdownlist (set value to dropdownlist with JavaScript)

Source: Internet
Author: User

Common Methods for JavaScript dropdownlist operations, from ASP. NET Forum, nc01

 

 

<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " DDL. aspx. CS " Inherits = " DDL "   %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head Runat = "Server" >
< Title > Untitled page </ Title >
< Script Type = "Text/JavaScript" >
<! --
Function Setdropdownlist (elementref, valuetosetto)
{
VaR Isfound =   False ;

For ( VaR I = 0 ; I < Elementref. Options. length; I ++ )
{
If (Elementref. Options [I]. Value = Valuetosetto)
{
Elementref. Options [I]. Selected =   True ;
Isfound =   True ;
}
}

If(Isfound= False)
Elementref. Options [0]. Selected= True;
}

Function Setdatoscga (DDL, strestadocarta)
{
Setdropdownlist (document. getelementbyid (DDL), strestadocarta );
}

Function Button1_onclick (){
Setdatoscga ( ' <% = Dropdownlist1.clientid %> ' , ' CC ' );
}

//-->
</Script>

</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Div >
< ASP: dropdownlist ID = "Dropdownlist1" Runat = "Server" >
< ASP: listitem > AA </ ASP: listitem >
< ASP: listitem > Bb </ ASP: listitem >
< ASP: listitem > CC </ ASP: listitem >
< ASP: listitem > Dd </ ASP: listitem >
< ASP: listitem > EE </ ASP: listitem >
</ ASP: dropdownlist >
< Input ID = "Button1" Type = "Button" Value = "Button" Onclick = "Return button1_onclick ()"   />
</ Div >
</ Form >
</ Body >
</ Html >

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.