?
Solved

Dynamic drop down select and field population?

Posted on 2007-07-31
4
Medium Priority
?
239 Views
Last Modified: 2013-11-19
Hi,

I'd like to be able to have a drop down select that will dynamically populate text fields w/ data when a user selects from the drop down list.

So far, I found an example that works and dynamically changes the text in just a div header when i select from the drop down

Code is as follows:
===============
<script type="text/javascript">
function getinfo()
{
var dna=('Company Name test')

var mylist=document.getElementById("info")
var val = document.getElementById("displayinfo").innerHTML=mylist.options[mylist.selectedIndex].title

if ( val == "a" ) { document.getElementById("displayinfo").innerHTML = dna; }
}
</script>

<select id="info" onchange="getinfo()">
<option title="a">Company Name</option>
<option title="b">Company Name1</option>
<option title="c">Company Name2</option>

</select>

<div id="displayinfo">The title goes here</div>
==============

However, when I try to modify this so that it changes the text in a text box field instead it doesn't seem to work.

Code as follows:
==============
<script type="text/javascript">
function getinfo()
{
var dna=('Company Name test')

var mylist=document.getElementById("info")
var val = document.getElementById("bob").innerHTML=mylist.options[mylist.selectedIndex].title

if ( val == "a" ) { document.getElementById("bob").innerHTML = dna; }
}
</script>

<select id="info" onchange="getinfo()">
<option title="a">Company Name</option>
<option title="b">Company Name1</option>
<option title="c">Company Name2</option>

</select>

<input type="text" id="bob">
<div id="displayinfo">The title goes here</div>
=============
Anyone have any idea why this doesn't work?
0
Comment
Question by:DImhoff1
  • 2
  • 2
4 Comments
 
LVL 6

Assisted Solution

by:SirCrofty
SirCrofty earned 800 total points
ID: 19601649
I thiink you just need to change this line

document.getElementById("bob").innerHTML = dna;

to

document.getElementById("bob").value = dna;
0
 
LVL 6

Assisted Solution

by:SirCrofty
SirCrofty earned 800 total points
ID: 19601656
I thiink you just need to change this line

document.getElementById("bob").innerHTML = dna;

to

document.getElementById("bob").value = dna;
0
 
LVL 14

Assisted Solution

by:bugs021997
bugs021997 earned 1200 total points
ID: 19601687
The problem in your code is...

var val = document.getElementById("bob").innerHTML=mylist.options[mylist.selectedIndex].title

You are trying to specify innerHTML to a TEXTBOX, which is wrong....

Change that line to as below...

var val = document.getElementById("bob").value=mylist.options[mylist.selectedIndex].title
0
 
LVL 14

Accepted Solution

by:
bugs021997 earned 1200 total points
ID: 19601720
@SirCrofty, I apologies, did not refresh before posting...


But two lines in @DImhoff1

Change

var val = document.getElementById("bob").innerHTML=mylist.options[mylist.selectedIndex].title

To

var val = document.getElementById("bob").value=mylist.options[mylist.selectedIndex].title



AND Change

if ( val == "a" ) { document.getElementById("bob").innerHTML = dna; }

TO

if ( val == "a" ) { document.getElementById("bob").value= dna; }
0

Featured Post

Industry Leaders: 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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
This video teaches users how to migrate an existing Wordpress website to a new domain.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

749 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