Solved

Get Value OnChange

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

770 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