I need to submit COUNTRY CODE to URL based on the selected country value.
Im using Intl-Tel-Input for this: https://github.com/jackocnr/intl-tel-input
Here is HTML code:
<form id="redirform" method="GET" action="#link">
<div class="gtd-form-wrapper">
<input type="hidden" id="country" name="country">
<div class="form-group">
<input name="phone" pattern="[0-9]*" id="phone" class="f w-input" data-value-missing="Use numbers only. No country code! No whitespaces!" required="required" placeholder="Phone">
</div>
<div class="form-group">
<button class="submit-button w-button gtd-form-submit" type="submit">SUBMIT</button>
</div>
</form>
Here is jQuery:
var input = document.querySelector("#phone");
window.intlTelInput(input, {
initialCountry: "auto",
geoIpLookup: function(success, failure) {
$.get("https://ipinfo.io/", function() {}, "jsonp").always(function(resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
success(countryCode);
});
},
});
input.addEventListener('countrychange', function () {
$('#country').val(iti.getSelectedCountryData().iso2);
});
$('#redirform').on('submit',function(){
var $input = $(this).find("input[name=country]");
$('#country').val(iti.getSelectedCountryData().iso2);
});
Here is picture of what I have and what I need: PICTURE CLICK TO OPEN