Solved

dropdown list onchange to update span (label)

Posted on 2008-10-06
2
612 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
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…

691 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