Solved

dropdown list onchange to update span (label)

Posted on 2008-10-06
2
608 Views
Last Modified: 2012-05-05
I have a label called lblField1, and a drop down called ddlField1... when ddlField1 changes I want to update the text in lblField1 to read whatever the selected text reads in ddlField1.

To do this I am attempting to set the onchange attribute as below, however this does not work.

<select name="ctl00$ContentPlaceHolder1$ddlField1" id="ctl00_ContentPlaceHolder1_ddlField1" onchange="document.getElementById("ctl00_ContentPlaceHolder1_lblField1").innerHtml=document.getElementById("ctl00_ContentPlaceHolder1_ddlField1").selectedValue;">


0
Comment
Question by:craigdev
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22654906
javascript is case sensitive. Change:
.innerHtml

to:
.innerHTML

If the problem persists, try:
<select name="ctl00$ContentPlaceHolder1$ddlField1" id="ctl00_ContentPlaceHolder1_ddlField1" onchange="document.getElementById("ctl00_ContentPlaceHolder1_lblField1").innerHTML=document.getElementById("ctl00_ContentPlaceHolder1_ddlField1").value;">
OR:
<select name="ctl00$ContentPlaceHolder1$ddlField1" id="ctl00_ContentPlaceHolder1_ddlField1" onchange="document.getElementById("ctl00_ContentPlaceHolder1_lblField1").innerHTML=document.getElementById("ctl00_ContentPlaceHolder1_ddlField1").options[ document.getElementById("ctl00_ContentPlaceHolder1_ddlField1").selectedIndex ].value;"> 
OR if you prefer the text:
<select name="ctl00$ContentPlaceHolder1$ddlField1" id="ctl00_ContentPlaceHolder1_ddlField1" onchange="document.getElementById("ctl00_ContentPlaceHolder1_lblField1").innerHTML=document.getElementById("ctl00_ContentPlaceHolder1_ddlField1").options[ document.getElementById("ctl00_ContentPlaceHolder1_ddlField1").selectedIndex ].text;">

Open in new window

0
 
LVL 1

Author Closing Comment

by:craigdev
ID: 31503642
brilliant, thank you!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

815 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

9 Experts available now in Live!

Get 1:1 Help Now