Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript drop downs

Status
Not open for further replies.

dzigner

Technical User
Apr 25, 2004
6
hi
i have 2 dynamic js drop downs, 1st is country, 2nd is cities.
I need a code that will create a htm table(not based on db), with values based on chosen country and city.
Right now the table has all countries/cities/values. This needs to be refreshed when country/city is chosen above.
thanks

Dzigner
 
Something like this?
Code:
<html>
<head>
<title>Countries and City Data</title>
<style type="text/css">
<!--

#country-city tr {
        display: none;
        }

#country-city tr.heads {
        display: block;
        }

-->
</style>
<script type="text/javascript">
<!--

var last = null;
function showCityCountry(frm)
{
  var countrysel = frm.elements['country'];
  var country = countrysel.options[countrysel.selectedIndex].value;

  var citysel = frm.elements['city'];
  var city = citysel.options[citysel.selectedIndex].value;

  var selid = country + "_" + city;
  var r = document.getElementById(selid);
  if (!r)
    return;
  if (last != null)
    last.style.display = "none";
  r.style.display = "block";
  last = r;
}

// -->
</script>
</head>
<body>
<form name="frm" id="frm">
 <select name="country" onchange="showCityCountry(this.form);">
  <option value="england">England</option>
  <option value="usa">United States of America</option>
 </select>
 <select name="city" onchange="showCityCountry(this.form);">
  <option value="london">London</option>
  <option value="washington">Washington D.C.</option>
 </select>
</form>

<table id="country-city">
 <tr class="heads">
  <th>Country</th>
  <th>City</th>
 </tr>
 <tr id="england_london">
  <td>England</td>
  <td>London</td>
 </tr>
 <tr id="usa_washington">
  <td>United States of America</td>
  <td>Washington D.C.</td>
 </tr>
</table>

</body>
</html>

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
chess;

we should go into business together.

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
[rofl]
Sorry; private joke. (Hint: Where have you seen me post this before?)




Might not be a bad idea though...

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
hi
thank you for your reply. i'll try out the code and let you know what happens.
happy.gif

thanks so much for your time and effort.

Dzigner
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top