trying to do something similar to the country code listener drop down but with a text box which should populate with the country code (so that I can subsequently use the value in PHP code).
Adding the event listener doesn't work:
<script>
$(document).ready(function(){
$("#mobile").intlTelInput({
onlyCountries: ["au","ca","us","nz","gb"],
utilsScript: "<?php echo get_template_directory_uri(); ?>/intl-tel-input/build/js/utils.js",
geoIpLookup: function(callback) {
$.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
callback(countryCode);
});
},
initialCountry: "auto"
}).addEventListener('countrychange', function() {
$("#country_code").value = "changed"
});;
$('#verify').attr('disabled','disabled');
$("#mobile").on('input', function() {
if ($("#mobile").intlTelInput("isValidNumber")) {
$('#verify').removeAttr('disabled');
$("#country_code").innerHTML = "changed"
} else {
$('#verify').attr('disabled','disabled');
}
});
$("#register-form").submit(function() {
$("#mobile").val($("#mobile").intlTelInput("getNumber"));
});
});
</script>