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

Posted on 2009-04-24
Last Modified: 2013-12-14
using html  drop down list and java script how to do automatic populate for country states and thier capital
Question by:Aravind17
    LVL 1

    Expert Comment

    Could you clarify this slightly?
    What is in the drop down list? What do you want to populate?

    Author Comment

    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
    LVL 1

    Accepted Solution

    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. ( 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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now