SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast almtechnology's Avatar
    Join Date
    Sep 2006
    Location
    Karachi,Pakistan
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem of multiple combo box

    hi

    i hv two combo box in javascript

    in 1st combo there r names of countries and in other cities
    i want that if i select usa 2 combo box shows cities of us
    if i select uk it shows cities of uk
    so provide me the code of above

  2. #2
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    meta http-equiv="Content-Style-Type" content="text/css">
    <
    meta http-equiv="Content-Script-Type" content="text/javascript">
    <
    script type="text/javascript">
    var 
    arr =[];//all the data's unsorted array
    arr['istanbul']=['uskudar','Beyoglu','sisli','Kadikoy'];
    arr['izmir']=['Konak','Bornova','Karsiyaka','Buca','Menemen','Gaziemir'];
    //you may add as many other elements as you want

    function create(s){
    var 
    rootdocument.getElementById('states');
    while(
    root.hasChildNodes()){//removes the old options
    root.removeChild(root.childNodes[0])
    }
    if(
    s.selectedIndex>0){//if a country is selected
    var v=s.value;
    for(var 
    i=0;i<arr[v].length;i++){
    var 
    oOpt document.createElement('option');//creates element option
    oOpt.setAttribute('value',arr[v][i]);//sets the value
    oOpt.appendChild(document.createTextNode(arr[v][i]));//sets the text
    root.appendChild(oOpt);//appends the option to the select element
    }
    }
    }
    </script>
    </head>
    <body>
    <select id="countries" onchange="create(this)">
    <option>Bir şehir seÁ</option>
    <option value="istanbul">istanbul</option>
    <option value="izmir">izmir</option>
    </select>

    <select id="states">
    </select>
    </body>
    </html> 

    http://www.webdeveloper.com/forum/s...8971#post628971
    Last edited by muazzez; Sep 29, 2006 at 12:04.

  3. #3
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's another one: xSelect.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •