Solved

Get Value OnChange

Posted on 2009-07-08
5
401 Views
Last Modified: 2012-06-21
I have a dropdown that i set a dynamic id, onChange i want to get the value of the dropdown dynamic id.

I want to dynamically add the on change attribute to something like:

mydropdownlist.attributes.add("OnChange",'GetMyValuefortheDynamicID')




Dynamic id for dropdown: id can be any number given to it
 

<asp:dropdownlist runat="server" id="12345">

<listitem>a</listitem>

<listitem>b</listitem>

<listitem>c</listitem>

</asp:dropdownlist>

Open in new window

0
Comment
Question by:Padre_Corleone
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:jainnaveen
ID: 24801314
this.id in the function will dropdown list id
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 24801322
i have the Id but need the value when user changes dropdown though
0
 
LVL 2

Accepted Solution

by:
jainnaveen earned 500 total points
ID: 24801373
mydropdownlist.attributes.add("OnChange",'getValue(this.id)')

function getValue(sel_id)
{
      var list = document.getElementById(sel_id)
      alert(list.options[list.selectedIndex].value)
}
0
 
LVL 9

Expert Comment

by:Graceful_Penguin
ID: 24801376
I don't know asp but why don't you output the onChange event as an attribute of the select from the server where you generate the html for the select?
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 24801444
thanks jainnaveen that did it.

Graceful one: i am trying to avoid using server side to improve performance.  thanks.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now