I using intlTelInput for the telephone & mobile field on asp.net webform website.
At present i am using it as a basic plugin as show in this example
var input = $("#ContentPlaceHolder1_txtPhone"), output = $("#output");
var country = $("#ContentPlaceHolder1_ddCountry");
input.intlTelInput({
preferredCountries: ['ae'],
autoHideDialCode: true,
nationalMode: false,
utilsScript: "../../Scripts/phone/js/utils.js" // just for formatting/placeholders etc
});
Now i am trying to sync it with the Country drop-down so that when user select the country it then automatically select the Telephone Fields & Mobile field on web-form with the country in telephone fields.
I tried to use this example but it is not working either it break the plugin or it downt work
http://intl-tel-input.com/node_modules/intl-tel-input/examples/gen/country-sync.html
Code which i tried
var countryData = $.fn.intlTelInput.getCountryData(),
telInput = $("#ContentPlaceHolder1_txtPhone"),
addressDropdown = $("#ContentPlaceHolder1_ddCountry");
// set it's initial value
//var initialCountry = telInput.intlTelInput("getSelectedCountryData").iso2;
//addressDropdown.val(initialCountry);
// listen to the telephone input for changes
telInput.on("countrychange", function (e, countryData) {
addressDropdown.val(countryData.iso2);
});
// listen to the address dropdown for changes
addressDropdown.change(function () {
telInput.intlTelInput("setCountry", $(this).val());
});
I have place code on codepen http://codepen.io/anon/pen/wgzppg.
I am not sure where i am doing it wrong. i tried few thing without any luck.
I pull data for country dropdown from database table not the plugin so that may be causing issue somewhere. but country code are matching also.