Link to home
Start Free TrialLog in
Avatar of paulheinisch
paulheinisch

asked on

Dropdown list and populating a textbox

I have the dropdown list working for me, but I want to be able to fill a textbox with an item from the same mysql table. The dropdown list display one item from the table and when the user selects the item from the drop down list, I need it to display another item from that record. So for example the sql database has a table called airports. Within the table three fields: id, name, city. The drop down list shows the name, i want the textbox to then show the city. Help please!

 
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands 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
Avatar of paulheinisch
paulheinisch

ASKER

I'm getting an undefined in the text box...what am I missing?
Sorry, not an undefined message , but a javascript error stating: "airport is undefinded"
Yes, it should have been airports[selBox.value] rather than airport[selBox.value];

-r-
Yea I did catch that...what happens now (after changing the airport to airports) is when I select an item on the dropdownlist within the textbox I get undefined...so I know we are close!
Please try:

function setCity(selBox) {
  selBox.form.city.value = airport[selBox.options[selBox.selectedIndex].value];
}

-r-
Nope...still undefinded
change this line:
var airports = new Array();
into this:
var airport = new Array();

:D

HOpe this help,
Yea we caught this one...its was a typo in the first listing...still gets the same results...
Do you mind if you paste your HTML result here? Perhaps we can analyze the javascript error.
Here's the source output...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
      
<script type="text/javascript">
var trips = new Array();

1 = 'Venice';
2 = 'Los Angeles';function setDestination(selBox) {
  selBox.form.city.value = trips[selBox.options[selBox.selectedIndex].value];
;
}
</script>
<form name="test">
  <select name="trip" onchange="setDestination(this);">
  <option value="1">Greek Isles Oddessey</option><option value="2">Alaska Adventure</option>  </select>
  <input type="text" name="city" disabled="disabled" />
</form>

</body>
</html>
hmmm. that should have been:

<script type="text/javascript">
var trips = new Array();

trips[1] = 'Venice';
trips[2] = 'Los Angeles';function setDestination(selBox) {
  selBox.form.city.value = trips[selBox.options[selBox.selectedIndex].value];
;
}


Can you double check that the line below is as it is:
$javascript .= "\ntrips[".$id."] = '$city';";

-r-
Roonaan is right, you need to correctly asign the array whith trips[1] = 'Venice', instead of 1='Venice'.

On more thing, please check in the asignment to the textbox, I think it should be:
document.test.city.value = trips[selBox.options[selBox.selectedIndex].value];

Hope this help ;)
I found the mistake I was making- thank you ...yes I should have had this:

$javascript .= "\ntrips[$id] = '$trip_dest';";


var trips = new Array();


opps! Thank you