{"id":655,"date":"2018-08-27T00:00:00","date_gmt":"2018-08-27T00:00:00","guid":{"rendered":"https:\/\/wp3.geodatasource.com\/tutorials\/add-city-dropdown-country-region-dropdown-menu\/"},"modified":"2026-01-16T01:26:27","modified_gmt":"2026-01-16T01:26:27","password":"","slug":"add-city-dropdown-country-region-dropdown-menu","status":"publish","type":"docs","link":"https:\/\/www.geodatasource.com\/resources\/tutorials\/add-city-dropdown-country-region-dropdown-menu\/","title":{"rendered":"How to add City DropDown to Country-Region DropDown Menu"},"content":{"rendered":"\n<p>Country-Region DropDown Menu is a JavaScript based dropdown menu that allows users to implement country-region list effortlessly. The region names are automatically refreshed and filled based on the country selection. And, the implementation is simple, you just need to edit a few lines of code by entering the pre-defined class name and attribute into the country and region dropdown menu respectively to make them work. In addition, there are a few more options users may configure to make the dropdown look fabulous like the default country selection, flag icon and so on.<\/p>\n\n\n\n<p>However, this open source dropdown menu only supports up to region level. Cities data was not available in this free version. And, this tutorial is going to show you with step-by-step instruction on how to add cities dropdown to Country-Region DropDown Menu.<\/p>\n\n\n\n<p>1. Get and download World Major Cities Database from <a href=\"https:\/\/www.geodatasource.com\/software\/world-major-cities-drop-down-list-source-codes\">https:\/\/www.geodatasource.com\/software\/world-major-cities-drop-down-list-source-codes<\/a><\/p>\n\n\n\n<p>2. Unzip the downloaded <strong>GEODATASOURCE-WORLD-MAJOR-CITIES-SOURCE-CODES.ZIP<\/strong> file.<\/p>\n\n\n\n<p>3. Import the database into MySQL database. Note: Please refer to the sql file in the unzipped file.<\/p>\n\n\n\n<p>4. Download Country-Region DropDown Menu at <a href=\"https:\/\/github.com\/geodatasource\/country-region-dropdown-menu\">https:\/\/github.com\/geodatasource\/country-region-dropdown-menu<\/a><\/p>\n\n\n\n<p>5. Run the following code in your site.<\/p>\n\n\n\n<div class=\"betterdocs-code-snippet-wrapper theme-light betterdocs-code-snippet-d89ad4f2\"\n     id=\"betterdocs-code-snippet-d89ad4f2\"\n     data-language=\"php\"\n     data-copy-button=\"true\">\n\n            <div class=\"betterdocs-code-snippet-header betterdocs-file-preview-header\">\n        <div class=\"betterdocs-file-preview-left\">\n                            <div class=\"betterdocs-traffic-lights\">\n                    <span class=\"traffic-light traffic-light-red\"><\/span>\n                    <span class=\"traffic-light traffic-light-yellow\"><\/span>\n                    <span class=\"traffic-light traffic-light-green\"><\/span>\n                <\/div>\n            \n            <div class=\"betterdocs-file-info\">\n                \n                            <\/div>\n        <\/div>\n\n        <div class=\"betterdocs-file-preview-right\">\n                            <div class=\"betterdocs-code-snippet-copy-container\">\n                    <button class=\"betterdocs-code-snippet-copy-button\"\n                            type=\"button\"\n                            data-clipboard-target=\"#betterdocs-code-snippet-d89ad4f2 .betterdocs-code-snippet-code code\"\n                            aria-label=\"Copy code to clipboard\">\n                        <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1ZM19 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H19C20.1 23 21 22.1 21 21V7C21 5.9 20.1 5 19 5ZM19 21H8V7H19V21Z\" fill=\"currentColor\"\/>\n                        <\/svg>\n                    <\/button>\n                                            <div class=\"betterdocs-code-snippet-tooltip\">Copy to clipboard<\/div>\n                                    <\/div>\n                    <\/div>\n        <\/div>\n    \n    <div class=\"betterdocs-code-snippet-content\">\n        \n        <pre class=\"betterdocs-code-snippet-code language-php\"><code>&lt;?php\n$mydbusername = &quot;[your username]&quot;;\n$mydbpassword = &quot;[your password]&quot;;\n$mydbserver = &quot;localhost&quot;;\n\n$conn = new mysqli($mydbserver, $mydbusername, $mydbpassword);\n\nif (!$conn) {\n  die(&#039;Could not connect: &#039; . $conn-&gt;connect_error);\n}\n\n$conn-&gt;select_db(&quot;countrystatecitydb&quot;) or die(&#039;Could not select database&#039;);\n\n$conn-&gt;query(&quot;SET NAMES &#039;utf8&#039;&quot;);\n\n$sqlStr = &quot;SELECT STATE, GROUP_CONCAT(CITY_NAME SEPARATOR &#039;| &#039;) AS CITY FROM countrystatecity\nWHERE STATE != &#039;-&#039;\nGROUP BY STATE&quot;;\n\n$rs1 = $conn-&gt;query($sqlStr);\n\nif (!$rs1) {\n  die(&#039;Query Error: &#039; . $conn-&gt;error);\n}\n\n?&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\n    &lt;title&gt;Country-Region DropDown Menu with Cities&lt;\/title&gt;\n    &lt;script src=&quot;dist\/geodatasource-crc.min.js&quot;&gt;&lt;\/script&gt;\n    &lt;script src=&quot;\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.12.4\/jquery.min.js&quot;&gt;&lt;\/script&gt;\n    &lt;script src=&quot;\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1.12.1\/jquery-ui.min.js&quot;&gt;&lt;\/script&gt;\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;\/\/code.jquery.com\/ui\/1.12.1\/themes\/base\/jquery-ui.css&quot;&gt;\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;dist\/geodatasource-countryflag.css&quot;&gt;\n&lt;?php\necho &#039;&lt;script type=&quot;text\/javascript&quot;&gt;&#039;;\necho &#039;var region_cities = {};&#039;;\nwhile ($row = $rs1-&gt;fetch_assoc()) {\necho &#039;region_cities[&quot;&#039; . $row[&quot;STATE&quot;] . &#039;&quot;] = &quot;&#039; . $row[&quot;CITY&quot;] . &#039;&quot;;&#039;;\n}\necho &#039;&lt;\/script&gt;&#039;;\n?&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n\n    &lt;h2&gt;Country-Region DropDown Menu Example&lt;\/h2&gt;\n\n    &lt;div&gt;\n        &lt;p&gt;Example:&lt;\/p&gt;\n\n        &lt;p&gt;\n            Country: &lt;select class=&quot;gds-cr&quot; country-data-region-id=&quot;gds-cr-example&quot;&gt;&lt;\/select&gt;\n\n            Region: &lt;select id=&quot;gds-cr-example&quot; region-data-city-id=&quot;gds-cr-city_example&quot; &gt;&lt;\/select&gt;\n\n            City: &lt;select id=&quot;gds-cr-city_example&quot; &gt;&lt;\/select&gt;\n        &lt;\/p&gt;\n    &lt;\/div&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;\n&lt;?php\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n    <\/div>\n<\/div>\n\n<script type=\"text\/javascript\">\ndocument.addEventListener('DOMContentLoaded', function() {\n    \/\/ Initialize copy functionality for this specific snippet\n    const snippet = document.getElementById('betterdocs-code-snippet-d89ad4f2');\n    if (snippet && window.BetterDocsCodeSnippet) {\n        window.BetterDocsCodeSnippet.initCopyButton(snippet);\n    }\n});\n<\/script>\n\n\n\n<p>6. Done.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Country-Region DropDown Menu is a JavaScript based dropdown menu that allows users to implement country-region list effortlessly. The region names [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"doc_category":[21],"doc_tag":[],"class_list":["post-655","docs","type-docs","status-publish","hentry","doc_category-technical"],"year_month":"2026-06","word_count":189,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"hexasoft","author_nicename":"hexasoft","author_url":"https:\/\/www.geodatasource.com\/resources\/author\/hexasoft\/"},"doc_category_info":[{"term_name":"Technical","term_url":"https:\/\/www.geodatasource.com\/resources\/categories\/technical\/"}],"doc_tag_info":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to add City DropDown to Country-Region DropDown Menu |<\/title>\n<meta name=\"description\" content=\"This tutorial shows how to add City DropDown to GeoDataSource Country-Region DropDown Menu. Read about it to learn more details.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.geodatasource.com\/resources\/tutorials\/add-city-dropdown-country-region-dropdown-menu\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add City DropDown to Country-Region DropDown Menu |\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows how to add City DropDown to GeoDataSource Country-Region DropDown Menu. Read about it to learn more details.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.geodatasource.com\/resources\/tutorials\/add-city-dropdown-country-region-dropdown-menu\/\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/geodatasource\/\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-16T01:26:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.geodatasource.com\/resources\/wp-content\/uploads\/2021\/05\/banner-articles-and-tutorials.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@_geodatasource\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/tutorials\\\/add-city-dropdown-country-region-dropdown-menu\\\/\",\"url\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/tutorials\\\/add-city-dropdown-country-region-dropdown-menu\\\/\",\"name\":\"How to add City DropDown to Country-Region DropDown Menu |\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/#website\"},\"datePublished\":\"2018-08-27T00:00:00+00:00\",\"dateModified\":\"2026-01-16T01:26:27+00:00\",\"description\":\"This tutorial shows how to add City DropDown to GeoDataSource Country-Region DropDown Menu. Read about it to learn more details.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/tutorials\\\/add-city-dropdown-country-region-dropdown-menu\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/tutorials\\\/add-city-dropdown-country-region-dropdown-menu\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/tutorials\\\/add-city-dropdown-country-region-dropdown-menu\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials\",\"item\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to add City DropDown to Country-Region DropDown Menu\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/#website\",\"url\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/\",\"name\":\"GeoDataSource Articles & Tutorials\",\"description\":\"Resources About GeoDataSource Services\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/#organization\",\"name\":\"GeoDataSource.com\",\"url\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/logo-e1564122827936.png\",\"contentUrl\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/logo-e1564122827936.png\",\"width\":220,\"height\":27,\"caption\":\"GeoDataSource.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.geodatasource.com\\\/resources\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/geodatasource\\\/\",\"https:\\\/\\\/x.com\\\/_geodatasource\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add City DropDown to Country-Region DropDown Menu |","description":"This tutorial shows how to add City DropDown to GeoDataSource Country-Region DropDown Menu. Read about it to learn more details.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.geodatasource.com\/resources\/tutorials\/add-city-dropdown-country-region-dropdown-menu\/","og_locale":"en_US","og_type":"article","og_title":"How to add City DropDown to Country-Region DropDown Menu |","og_description":"This tutorial shows how to add City DropDown to GeoDataSource Country-Region DropDown Menu. Read about it to learn more details.","og_url":"https:\/\/www.geodatasource.com\/resources\/tutorials\/add-city-dropdown-country-region-dropdown-menu\/","article_publisher":"https:\/\/www.facebook.com\/geodatasource\/","article_modified_time":"2026-01-16T01:26:27+00:00","og_image":[{"width":1200,"height":600,"url":"https:\/\/www.geodatasource.com\/resources\/wp-content\/uploads\/2021\/05\/banner-articles-and-tutorials.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@_geodatasource","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.geodatasource.com\/resources\/tutorials\/add-city-dropdown-country-region-dropdown-menu\/","url":"https:\/\/www.geodatasource.com\/resources\/tutorials\/add-city-dropdown-country-region-dropdown-menu\/","name":"How to add City DropDown to Country-Region DropDown Menu |","isPartOf":{"@id":"https:\/\/www.geodatasource.com\/resources\/#website"},"datePublished":"2018-08-27T00:00:00+00:00","dateModified":"2026-01-16T01:26:27+00:00","description":"This tutorial shows how to add City DropDown to GeoDataSource Country-Region DropDown Menu. Read about it to learn more details.","breadcrumb":{"@id":"https:\/\/www.geodatasource.com\/resources\/tutorials\/add-city-dropdown-country-region-dropdown-menu\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.geodatasource.com\/resources\/tutorials\/add-city-dropdown-country-region-dropdown-menu\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.geodatasource.com\/resources\/tutorials\/add-city-dropdown-country-region-dropdown-menu\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.geodatasource.com\/resources\/"},{"@type":"ListItem","position":2,"name":"Tutorials","item":"https:\/\/www.geodatasource.com\/resources\/tutorials\/"},{"@type":"ListItem","position":3,"name":"How to add City DropDown to Country-Region DropDown Menu"}]},{"@type":"WebSite","@id":"https:\/\/www.geodatasource.com\/resources\/#website","url":"https:\/\/www.geodatasource.com\/resources\/","name":"GeoDataSource Articles & Tutorials","description":"Resources About GeoDataSource Services","publisher":{"@id":"https:\/\/www.geodatasource.com\/resources\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.geodatasource.com\/resources\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.geodatasource.com\/resources\/#organization","name":"GeoDataSource.com","url":"https:\/\/www.geodatasource.com\/resources\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.geodatasource.com\/resources\/#\/schema\/logo\/image\/","url":"https:\/\/www.geodatasource.com\/resources\/wp-content\/uploads\/2019\/07\/logo-e1564122827936.png","contentUrl":"https:\/\/www.geodatasource.com\/resources\/wp-content\/uploads\/2019\/07\/logo-e1564122827936.png","width":220,"height":27,"caption":"GeoDataSource.com"},"image":{"@id":"https:\/\/www.geodatasource.com\/resources\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/geodatasource\/","https:\/\/x.com\/_geodatasource"]}]}},"_links":{"self":[{"href":"https:\/\/www.geodatasource.com\/resources\/wp-json\/wp\/v2\/docs\/655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.geodatasource.com\/resources\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.geodatasource.com\/resources\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.geodatasource.com\/resources\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.geodatasource.com\/resources\/wp-json\/wp\/v2\/comments?post=655"}],"version-history":[{"count":1,"href":"https:\/\/www.geodatasource.com\/resources\/wp-json\/wp\/v2\/docs\/655\/revisions"}],"predecessor-version":[{"id":722,"href":"https:\/\/www.geodatasource.com\/resources\/wp-json\/wp\/v2\/docs\/655\/revisions\/722"}],"wp:attachment":[{"href":"https:\/\/www.geodatasource.com\/resources\/wp-json\/wp\/v2\/media?parent=655"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.geodatasource.com\/resources\/wp-json\/wp\/v2\/doc_category?post=655"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.geodatasource.com\/resources\/wp-json\/wp\/v2\/doc_tag?post=655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}