A Quick jQuery-Based Country Picker With Flags | Country Select JS

Country Select JS is a jQuery plugin to select a country, based on the international phone input plugin.

Adds a flag dropdown to any input, which lists all countries in English and the dominant national language next to their flags.

Features

  • Automatically select a country by user type.
  • Go to the country dropdown by typing the country name or using the up/down keys.
  • Selecting a country from the drop-down list will update the country name in the input.
  • A dropdown appears above or below the input based on the available space/scroll position.
  • Lots of customizable configuration options, as well as general methods of interaction.
  • Optionally, a field related to the two-character ISO country code in the selection can be updated.

Must Read: One Easy-to-use 230+ Country Flags Component for Vue.js

How to make use of it:

1. Link the stylesheet (note that this references the image flags.png).

<link rel="stylesheet" href="build/css/countrySelect.css">

2. Add the plugin script and initialize it on your input element.

<input type="text" id="country">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="build/js/countrySelect.min.js"></script>
<script>
  $("#country").countrySelect();
</script>

3. Optional: add an extra input field (with type hidden or text) named the same as your selector input appended with “_code“. This will automatically be updated with the ISO 3166-1 alpha-2 code for the selected country.

<input type="text" id="country" />
<input type="hidden" id="country_code" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="build/js/countrySelect.min.js"></script>
<script>
  $("#country").countrySelect();
</script>

4. Pass an (optional) object as a parameter to the countrySelect method when initializing the selector.

$("#country").countrySelect({
  defaultCountry: "jp",
  onlyCountries: ['us', 'gb', 'ch', 'ca', 'do', 'jp'],
  preferredCountries: ['ca', 'gb', 'us'],
  responsiveDropdown: true
});

Options

Note: any options that take country codes should be lowercase ISO 3166-1 alpha-2 code.

Must Read: Dynamically Populating an HTML Table Including Sorting and Filtering Functions | ECJSTable

defaultCountry
Type: String Default: ""
Set the default country by its country code. Otherwise, it will just be the first country on the list.

onlyCountries
Type: Array Default: undefined
Display only the countries you specify. Takes an array of country codes.

excludeCountries
Type: Array Default: undefined
Display only the countries not specified. Takes an array of country codes.

preferredCountries
Type: Array Default: ["us", "gb"]
Specify the countries to appear at the top of the list.

responsiveDropdown
Type: Boolean Default: false
Set the dropdown’s width to be the same as the input. This is automatically enabled for small screens.

localizedCountries
Type: Object Default: {}
Allows translating the countries by its given iso code.

See Demo And Download

country-dropdown-with-flags

Official Website(mrmarkfrench): Click Here

This superior jQuery/javascript plugin is developed by mrmarkfrench. For extra advanced usage, please go to the official website.

Related Posts

drag-drop-file-5x5-jq-uploader

Responsive Drag and Drop File Uploader/Download Plugin | 5x5_jq_uploader

5x5_jq_uploader plugin can be used to instantly create a drop file area and file queue with a little bit of preparation. Bootstrap is used for responsive planning…

Bootstrap-Dark-Mode

Stylesheet For Implementing Dark Mode with Bootstrap

Bootstrap Dark Mode provides a style sheet and two texts that allow you to implement Dark Mode on your website. Initially loaded based on user preferences, can…

responsive-navigation-menu

Multi-purpose Navigation Menu for Javascript Library | jQuery Corenav

coreNavigation is a multipurpose navigation menu for a jquery based javascript library, comes with more style, and is easy to integrate. 11 Default Menu 2 Responsive Navigation…

Simple-Multi-Select-Dropdown-Pure-Vanilla-Javascript

Simple Multi-Select Dropdown Pure Vanilla Javascript | multiSelect.js

MultiSelect.js is a simple, clean, and progressive JavaScript library designed for easy integration with any type of project or system. The design was heavily influenced by the…

Confetti-Falling-Animation-Effect-party

Confetti Falling Animation Effect In JavaScript | party.js

Party.js is a JavaScript library to brighten user site experience with visual effects! Celebrate success with dom confetti! The library is written in TypeScript and compiled into…

how-to-create-popup-in-html-with-css

How To Create A Popup in HTML with CSS

How to create popup in html with css – Popup without JavaScript is an elegant pop-up panel component with an animated scale, written in CSS. Have you…