Solved

dropdown list onchange to update span (label)

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to print dynamic Google map and directions? 1 23
how can i get the string decoded ? 2 28
Html CheckBox obtain Its Value 5 27
Html input text color the frame line 2 19
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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

792 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