Solved

Get Value OnChange

Posted on 2009-07-08
5
406 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Possible propagation problem 1 34
Duplicate Elements with JS / jQuery 3 24
Calculating percentage 2 27
AngularJS: ng-repeat 25 19
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

685 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