Link to home
Start Free TrialLog in
Avatar of DImhoff1
DImhoff1Flag for United States of America

asked on

Dynamic drop down select and field population?

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?
SOLUTION
Avatar of SirCrofty
SirCrofty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial