Solved

Get Value OnChange

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

920 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

17 Experts available now in Live!

Get 1:1 Help Now