Get the Dropdownlist text and value using Javascript from client side

Hi,

I am encountering a problem about how to get the Dropdownlist text and value using Javascript from client side. I am using C# in Visual Studio 2005 and Javasript . The example codes are like:

( In this example code, I would like to access the text and value of the DropDownListReports in the run() function of Javascript. How can I do that? Any ideas? Thanks a lot. )

protected void Page_Load(object sender, EventArgs e)

{

             if (!Page.IsPostBack)

              {

                    DropDownListReports.Items.Clear();

                    ListItem

listItem = new ListItem();

                    listItem.Text = "aText";

                    listItem.Value = "aValue;

                    DropDownListReports.Items.Add(listItem);

              }

}

 

on the its source page:

 

<

asp:DropDownList ID="DropDownListReports" Width = '300' runat="server" > </asp:DropDownList>

<input id="btnSubmit" type="button" value="Click to view report on another browser" onclick="run()" TabIndex="3" />

<

script type="text/javascript">

function

run()

{

     // ?????? for the example, please just using alert to show the pair of text and value for this dropdownlist.       Like:  alert(dropdownlist.text);

}


whuili
0
whuili_2006
2/5/2007 9:40:16 PM
asp.net.client-side 24353 articles. 1 followers. Follow

2 Replies
4928 Views

Similar Articles

[PageSpeed] 24

add the below code into your javascript function

alert(document.getElementById("<%=DropDownListReports.ClientID%>").options[document.getElementById("<%=DropDownListReports.ClientID%>").selectedIndex].text)

HC

------

Mark it as answered if it helps you


Haissam Abdul Malak
MCAD.NET
| Blog |
1
Haissam
2/5/2007 10:50:58 PM
Hi, 

To get the value and the Text you could use it like this,  

 

var ddlReport = document.getElementById("<%=DropDownListReports.ClientID%>");
var Text = ddlReport.options[ddlReport.selectedIndex].text; 
var Value = ddlReport.options[ddlReport.selectedIndex].value; 
 

 

 

 


Rajganesh
__________________________________________________
My Blog
If this post answers your question please mark it as Answered.
2
Rajganesh
2/6/2007 9:58:41 AM
Reply:

Web resources about - Get the Dropdownlist text and value using Javascript from client side - asp.net.client-side

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 1/22/2016 10:54:04 PM