I have been trying to get the Extension of the mobile number entered. Every other variable is working fine. The extension variable is returning Null. It seems that it is passing a null value to the POST.
<input type="tel" id="mobile" placeholder="Mobile Number" maxlength="10" >
<script>
//Initialize the plugin
$("#mobile").intlTelInput({
initialCountry: "auto",
nationalMode: "true",
utilsScript:'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/8.5.0/js/utils.js',
geoIpLookup: function(callback) {
$.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
callback(countryCode);
});
}
});
//Ajax Registration
$("#register").click(function(){
var email = $("#email").val();
var password = $("#password").val();
var confirmpassword = $("#confirmpassword").val();
var fname = $("#fname").val();
var lname = $("#lname").val();
var mobile = $("#mobile").val();
var role = $("#role").val();
var extension = $("#mobile").intlTelInput("getExtension");
var data = "email=" + email + "&password=" + password + "&fname=" + fname + "&lname=" + lname + "&mobile=" + mobile + "&role=" + role + "&confirmpassword=" + confirmpassword + "&extension=" + extension;
$.ajax({
type:"POST",
url:"includes/register.php?",
data:data,
success:function(data)
{
$("#register_output").html(data);
}
});
</script>
I believe the getExtension method is now deprecated. If you want the country code on its own, you can get it at iti.s.dialCode
. Something like this:
<label>Phone</label><input class="textbox" type="tel" name="phone" id="phone" value=""><br>
<script>
var input = document.querySelector('#phone');
var iti = intlTelInput(input, {
utilsScript: 'assets/tel-input/js/utils.js',
initialCountry: 'au'
});
$('#send').on('click', function(param) {
var fullPhone = "+" + iti.s.dialCode + iti.getNumber();
console.log(fullPhone)
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.