-
-
Save mpro9x/6f1bac9292c0f63b23676c17ac39d712 to your computer and use it in GitHub Desktop.
Here is the Country Code Select List JS, Please put this to the "Before Body End Tag"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src='https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/intlTelInput.min.js'></script> | |
<script> | |
// International telephone format | |
// $("#phone").intlTelInput(); | |
// get the country data from the plugin | |
var countryData = window.intlTelInputGlobals.getCountryData(), | |
input = document.querySelector("#phone"), | |
addressDropdown = document.querySelector("#country"); | |
// init plugin | |
var iti = window.intlTelInput(input, { | |
hiddenInput: "full_phone", | |
utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/utils.js" // just for formatting/placeholders etc | |
}); | |
// populate the country dropdown | |
for (var i = 0; i < countryData.length; i++) { | |
var country = countryData[i]; | |
var optionNode = document.createElement("option"); | |
optionNode.value = country.iso2; | |
var textNode = document.createTextNode(country.name); | |
optionNode.appendChild(textNode); | |
addressDropdown.appendChild(optionNode); | |
} | |
// set it's initial value | |
addressDropdown.value = iti.getSelectedCountryData().iso2; | |
// listen to the telephone input for changes | |
input.addEventListener('countrychange', function(e) { | |
addressDropdown.value = iti.getSelectedCountryData().iso2; | |
}); | |
// listen to the address dropdown for changes | |
addressDropdown.addEventListener('change', function() { | |
iti.setCountry(this.value); | |
}); | |
</script> | |
<script> | |
//Append Value To Phone Field | |
$("#phone").prop('value', '+1 '); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment