Solved

dropdown list onchange to update span (label)

Posted on 2008-10-06
2
610 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

Suggested Solutions

Title # Comments Views Activity
JS Event Does not Trigger From File 2 38
email validation 9 47
Compute age Html 2 23
Table doesn't show the lines! 3 23
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

680 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