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

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

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.

 

Easy Country Picker With Flags, Country Select JS Plugin/Github


See Demo And Download

Official Website(mrmarkfrench): Click Here

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

Share