SHARE
TWEET

Combo Box

aslv Aug 17th, 2014 1,062 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_start();
  3. $countryList = array(
  4.     "Africa" => array(
  5.         "DZ" => "Algeria",
  6.         "AO" => "Angola",
  7.         "BJ" => "Benin",
  8.         "BW" => "Botswana",
  9.         "BF" => "Burkina Faso",
  10.         "BI" => "Burundi",
  11.         "CM" => "Cameroon",
  12.         "CV" => "Cape Verde",
  13.         "CF" => "Central African Republic",
  14.         "TD" => "Chad",
  15.         "KM" => "Comoros",
  16.         "CG" => "Congo - Brazzaville",
  17.         "CD" => "Congo - Kinshasa",
  18.         "CI" => "Côte d’Ivoire",
  19.         "DJ" => "Djibouti",
  20.         "EG" => "Egypt",
  21.         "GQ" => "Equatorial Guinea",
  22.         "ER" => "Eritrea",
  23.         "ET" => "Ethiopia",
  24.         "GA" => "Gabon",
  25.         "GM" => "Gambia",
  26.         "GH" => "Ghana",
  27.         "GN" => "Guinea",
  28.         "GW" => "Guinea-Bissau",
  29.         "KE" => "Kenya",
  30.         "LS" => "Lesotho",
  31.         "LR" => "Liberia",
  32.         "LY" => "Libya",
  33.         "MG" => "Madagascar",
  34.         "MW" => "Malawi",
  35.         "ML" => "Mali",
  36.         "MR" => "Mauritania",
  37.         "MU" => "Mauritius",
  38.         "YT" => "Mayotte",
  39.         "MA" => "Morocco",
  40.         "MZ" => "Mozambique",
  41.         "NA" => "Namibia",
  42.         "NE" => "Niger",
  43.         "NG" => "Nigeria",
  44.         "RW" => "Rwanda",
  45.         "RE" => "Réunion",
  46.         "SH" => "Saint Helena",
  47.         "SN" => "Senegal",
  48.         "SC" => "Seychelles",
  49.         "SL" => "Sierra Leone",
  50.         "SO" => "Somalia",
  51.         "ZA" => "South Africa",
  52.         "SD" => "Sudan",
  53.         "SZ" => "Swaziland",
  54.         "ST" => "São Tomé and Príncipe",
  55.         "TZ" => "Tanzania",
  56.         "TG" => "Togo",
  57.         "TN" => "Tunisia",
  58.         "UG" => "Uganda",
  59.         "EH" => "Western Sahara",
  60.         "ZM" => "Zambia",
  61.         "ZW" => "Zimbabwe",
  62.     ),
  63.     "South America" => array(
  64.         "AR" => "Argentina",
  65.         "BO" => "Bolivia",
  66.         "BR" => "Brazil",
  67.         "CL" => "Chile",
  68.         "CO" => "Colombia",
  69.         "EC" => "Ecuador",
  70.         "GY" => "Guyana",
  71.         "PY" => "Paraguay",
  72.         "PE" => "Peru",
  73.         "SR" => "Suriname",
  74.         "UY" => "Uruguay",
  75.         "VE" => "Venezuela",
  76.     ),
  77.     "North America" => array(
  78.         "AI" => "Anguilla",
  79.         "AG" => "Antigua and Barbuda",
  80.         "AW" => "Aruba",
  81.         "BS" => "Bahamas",
  82.         "BB" => "Barbados",
  83.         "BZ" => "Belize",
  84.         "BM" => "Bermuda",
  85.         "VG" => "British Virgin Islands",
  86.         "CA" => "Canada",
  87.         "KY" => "Cayman Islands",
  88.         "CR" => "Costa Rica",
  89.         "CU" => "Cuba",
  90.         "DM" => "Dominica",
  91.         "DO" => "Dominican Republic",
  92.         "SV" => "El Salvador",
  93.         "FK" => "Falkland Islands",
  94.         "GF" => "French Guiana",
  95.         "GL" => "Greenland",
  96.         "GD" => "Grenada",
  97.         "GP" => "Guadeloupe",
  98.         "GT" => "Guatemala",
  99.         "HT" => "Haiti",
  100.         "HN" => "Honduras",
  101.         "JM" => "Jamaica",
  102.         "MQ" => "Martinique",
  103.         "MX" => "Mexico",
  104.         "MS" => "Montserrat",
  105.         "AN" => "Netherlands Antilles",
  106.         "NI" => "Nicaragua",
  107.         "PA" => "Panama",
  108.         "PR" => "Puerto Rico",
  109.         "BL" => "Saint Barthélemy",
  110.         "KN" => "Saint Kitts and Nevis",
  111.         "LC" => "Saint Lucia",
  112.         "MF" => "Saint Martin",
  113.         "PM" => "Saint Pierre and Miquelon",
  114.         "VC" => "Saint Vincent and the Grenadines",
  115.         "TT" => "Trinidad and Tobago",
  116.         "TC" => "Turks and Caicos Islands",
  117.         "VI" => "U.S. Virgin Islands",
  118.         "US" => "United States",
  119.  
  120.     ),
  121.     "Asia" => array(
  122.         "AF" => "Afghanistan",
  123.         "AM" => "Armenia",
  124.         "AZ" => "Azerbaijan",
  125.         "BH" => "Bahrain",
  126.         "BD" => "Bangladesh",
  127.         "BT" => "Bhutan",
  128.         "BN" => "Brunei",
  129.         "KH" => "Cambodia",
  130.         "CN" => "China",
  131.         "CY" => "Cyprus",
  132.         "GE" => "Georgia",
  133.         "HK" => "Hong Kong SAR China",
  134.         "IN" => "India",
  135.         "ID" => "Indonesia",
  136.         "IR" => "Iran",
  137.         "IQ" => "Iraq",
  138.         "IL" => "Israel",
  139.         "JP" => "Japan",
  140.         "JO" => "Jordan",
  141.         "KZ" => "Kazakhstan",
  142.         "KW" => "Kuwait",
  143.         "KG" => "Kyrgyzstan",
  144.         "LA" => "Laos",
  145.         "LB" => "Lebanon",
  146.         "MO" => "Macau SAR China",
  147.         "MY" => "Malaysia",
  148.         "MV" => "Maldives",
  149.         "MN" => "Mongolia",
  150.         "MM" => "Myanmar [Burma]",
  151.         "NP" => "Nepal",
  152.         "NT" => "Neutral Zone",
  153.         "KP" => "North Korea",
  154.         "OM" => "Oman",
  155.         "PK" => "Pakistan",
  156.         "PS" => "Palestinian Territories",
  157.         "YD" => "People's Democratic Republic of Yemen",
  158.         "PH" => "Philippines",
  159.         "QA" => "Qatar",
  160.         "SA" => "Saudi Arabia",
  161.         "SG" => "Singapore",
  162.         "KR" => "South Korea",
  163.         "LK" => "Sri Lanka",
  164.         "SY" => "Syria",
  165.         "TW" => "Taiwan",
  166.         "TJ" => "Tajikistan",
  167.         "TH" => "Thailand",
  168.         "TL" => "Timor-Leste",
  169.         "TR" => "Turkey",
  170.         "TM" => "Turkmenistan",
  171.         "AE" => "United Arab Emirates",
  172.         "UZ" => "Uzbekistan",
  173.         "VN" => "Vietnam",
  174.         "YE" => "Yemen",
  175.     ),
  176.     "Europe" => array(
  177.         "AL" => "Albania",
  178.         "AD" => "Andorra",
  179.         "AT" => "Austria",
  180.         "BY" => "Belarus",
  181.         "BE" => "Belgium",
  182.         "BA" => "Bosnia and Herzegovina",
  183.         "BG" => "Bulgaria",
  184.         "HR" => "Croatia",
  185.         "CY" => "Cyprus",
  186.         "CZ" => "Czech Republic",
  187.         "DK" => "Denmark",
  188.         "DD" => "East Germany",
  189.         "EE" => "Estonia",
  190.         "FO" => "Faroe Islands",
  191.         "FI" => "Finland",
  192.         "FR" => "France",
  193.         "DE" => "Germany",
  194.         "GI" => "Gibraltar",
  195.         "GR" => "Greece",
  196.         "GG" => "Guernsey",
  197.         "HU" => "Hungary",
  198.         "IS" => "Iceland",
  199.         "IE" => "Ireland",
  200.         "IM" => "Isle of Man",
  201.         "IT" => "Italy",
  202.         "JE" => "Jersey",
  203.         "LV" => "Latvia",
  204.         "LI" => "Liechtenstein",
  205.         "LT" => "Lithuania",
  206.         "LU" => "Luxembourg",
  207.         "MK" => "Macedonia",
  208.         "MT" => "Malta",
  209.         "FX" => "Metropolitan France",
  210.         "MD" => "Moldova",
  211.         "MC" => "Monaco",
  212.         "ME" => "Montenegro",
  213.         "NL" => "Netherlands",
  214.         "NO" => "Norway",
  215.         "PL" => "Poland",
  216.         "PT" => "Portugal",
  217.         "RO" => "Romania",
  218.         "RU" => "Russia",
  219.         "SM" => "San Marino",
  220.         "RS" => "Serbia",
  221.         "CS" => "Serbia and Montenegro",
  222.         "SK" => "Slovakia",
  223.         "SI" => "Slovenia",
  224.         "ES" => "Spain",
  225.         "SJ" => "Svalbard and Jan Mayen",
  226.         "SE" => "Sweden",
  227.         "CH" => "Switzerland",
  228.         "UA" => "Ukraine",
  229.         "SU" => "Union of Soviet Socialist Republics",
  230.         "GB" => "United Kingdom",
  231.         "VA" => "Vatican City",
  232.         "AX" => "Åland Islands",
  233.     ),
  234.     "Australia" => array(
  235.         "AS" => "American Samoa",
  236.         "AU" => "Australia",
  237.         "BV" => "Bouvet Island",
  238.         "IO" => "British Indian Ocean Territory",
  239.         "CX" => "Christmas Island",
  240.         "CC" => "Cocos [Keeling] Islands",
  241.         "CK" => "Cook Islands",
  242.         "FJ" => "Fiji",
  243.         "PF" => "French Polynesia",
  244.         "TF" => "French Southern Territories",
  245.         "GU" => "Guam",
  246.         "HM" => "Heard Island and McDonald Islands",
  247.         "KI" => "Kiribati",
  248.         "MH" => "Marshall Islands",
  249.         "FM" => "Micronesia",
  250.         "NR" => "Nauru",
  251.         "NC" => "New Caledonia",
  252.         "NZ" => "New Zealand",
  253.         "NU" => "Niue",
  254.         "NF" => "Norfolk Island",
  255.         "MP" => "Northern Mariana Islands",
  256.         "PW" => "Palau",
  257.         "PG" => "Papua New Guinea",
  258.         "PN" => "Pitcairn Islands",
  259.         "WS" => "Samoa",
  260.         "SB" => "Solomon Islands",
  261.         "GS" => "South Georgia and the South Sandwich Islands",
  262.         "TK" => "Tokelau",
  263.         "TO" => "Tonga",
  264.         "TV" => "Tuvalu",
  265.         "UM" => "U.S. Minor Outlying Islands",
  266.         "VU" => "Vanuatu",
  267.         "WF" => "Wallis and Futuna",
  268.     ),
  269.     "Antarctica" => array(
  270.     )
  271. );
  272. ?>
  273. <!DOCTYPE html>
  274. <html>
  275.     <head>
  276.         <title>Combo Box</title>
  277.         <style type="text/css">
  278.             select, input {
  279.                 display: inline-block;
  280.                 margin: 5px;
  281.             }
  282.         </style>
  283.     </head>
  284.     <body>
  285.         <form id="continents" action="" method="post">
  286.             <select name="continent" required onchange="document.getElementById('continents').submit()">
  287.                 <option selected disabled hidden value=""></option>
  288.                 <option value="Africa">Africa</option>
  289.                 <option value="Antarctica">Antarctica</option>
  290.                 <option value="Asia">Asia</option>
  291.                 <option value="Australia">Australia</option>
  292.                 <option value="Europe">Europe</option>
  293.                 <option value="North America">North America</option>
  294.                 <option value="South America">South America</option>
  295.             </select>
  296.         </form>
  297.         <form id="countries" action="" method="post">
  298.             <input list="list-countries" name="country" autocomplete="off" />
  299.             <input type="submit" value="Choose" />
  300.             <datalist id="list-countries">
  301.                 <?php
  302.                 if (!empty($_POST) && isset($_POST['continent'])) {
  303.                     $continent = $_POST['continent'];
  304.                     $countries = $countryList[$continent];
  305.                     foreach ($countries as $country) {
  306.                         echo option($country);
  307.                     }
  308.                     $_SESSION['continent'] = $continent;
  309.                 }
  310.                 function option($value) {
  311.                     return '<option value="' . $value . '" />';
  312.                 }
  313.                 ?>
  314.             </datalist>
  315.         </form>
  316.         <?php
  317.         if (!empty($_POST) && isset($_POST['country'])) {
  318.             echo 'You chose ' . $_POST['country'];
  319.             if (isset($_SESSION['continent'])) {
  320.                 echo ' from ' . $_SESSION['continent'];
  321.             }
  322.             echo '!';
  323.         }
  324.         ?>
  325.     </body>
  326. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top