Solved

dropdown list onchange to update span (label)

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

759 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

18 Experts available now in Live!

Get 1:1 Help Now