[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 686
  • Last Modified:

using html drop down list and java script how to do automatic populate for country states and thier capital

using html  drop down list and java script how to do automatic populate for country states and thier capital
  • 2
1 Solution
Could you clarify this slightly?
What is in the drop down list? What do you want to populate?
Aravind17Author Commented:
HTML drop down list(select)

Eg:---- iam using two html  drop dwon(select) .in that one is state and another one is city,if i select the state ,the capitial city should be automatically populated .by using HTML and Javascript
Using a drop-down list to select the city would be too hard to just use with JavaScript alone, you would have *massive* lists. In this example I am using a textbox instead of a list for the city. If you want to use a dropdown list, I suggest you look at AJAX. (http://www.w3schools.com/Ajax/Default.Asp) I think it would be too much effort to use a dropdown list.
In the example below I am only catering for Alaska and Arkansas but you can add in the other states pretty easily.
Okay, you want something like this:
<script type="text/javascript">
function popCity(id) {
 document.getElementById("city").disabled = false;
 switch (id) {
  case "0";
   document.getElementById("city").value = "Juneau";
  case "1";
   document.getElementById("city").value = "Little Rock";
<form name="form1">
<select name="state" id="state">
<option name="AL" onclick="popCity(0);">Alaska</option>
<option name="AK" onclick="popCity(1);">Arkansas</option>
<input type="text" name="city" id="city" value="Please select state..." disabled="disabled">

Open in new window


Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now