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

x
  • 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
0
Aravind17
Asked:
Aravind17
  • 2
1 Solution
 
lesavareCommented:
Could you clarify this slightly?
What is in the drop down list? What do you want to populate?
0
 
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
0
 
lesavareCommented:
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:
<html>
<head>
<title>Example</title>
<script type="text/javascript">
function popCity(id) {
 document.getElementById("city").disabled = false;
 switch (id) {
  case "0";
   document.getElementById("city").value = "Juneau";
   break;
  case "1";
   document.getElementById("city").value = "Little Rock";
   break;
 }
}
</script>
</head>
<body>
<form name="form1">
<select name="state" id="state">
<option name="AL" onclick="popCity(0);">Alaska</option>
<option name="AK" onclick="popCity(1);">Arkansas</option>
</select>
<input type="text" name="city" id="city" value="Please select state..." disabled="disabled">
</form>
</body>
</html>

Open in new window

0

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