I am trying to follow jquery tutorial on .html to create input type number with country code in a form. However, in my case though flag is appearing to change, the country code is not added inside the input field as they show in the demo.
Following is the code they have provided:
<head>
<meta charset="utf-8">
<title>International Telephone Input</title>
<link rel="stylesheet" href="build/css/intlTelInput.css">
<link rel="stylesheet" href="build/css/demo.css">
</head>
<body>
<form>
<input id="mobile-number" type="tel">
<button type="submit">Submit</button>
</form>
<!-- Load jQuery from CDN so can run demo immediately -->
<script src=".11.1/jquery.min.js"></script>
<script src="build/js/intlTelInput.js"></script>
<script>
$("#mobile-number").intlTelInput({
//allowExtensions: true,
//autoFormat: false,
//autoHideDialCode: false,
//autoPlaceholder: false,
//defaultCountry: "auto",
//ipinfoToken: "yolo",
//nationalMode: false,
//numberType: "MOBILE",
//onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
//preferredCountries: ['cn', 'jp'],
//preventInvalidNumbers: true,
utilsScript: "lib/libphonenumber/build/utils.js"
});
</script>
Here is the link where I am trying to implement it: .html
I have tried changing the mented out options in script but it doesn't help.
I am trying to follow jquery tutorial on http://www.jqueryscript/form/jQuery-International-Telephone-Input-With-Flags-Dial-Codes.html to create input type number with country code in a form. However, in my case though flag is appearing to change, the country code is not added inside the input field as they show in the demo.
Following is the code they have provided:
<head>
<meta charset="utf-8">
<title>International Telephone Input</title>
<link rel="stylesheet" href="build/css/intlTelInput.css">
<link rel="stylesheet" href="build/css/demo.css">
</head>
<body>
<form>
<input id="mobile-number" type="tel">
<button type="submit">Submit</button>
</form>
<!-- Load jQuery from CDN so can run demo immediately -->
<script src="http://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="build/js/intlTelInput.js"></script>
<script>
$("#mobile-number").intlTelInput({
//allowExtensions: true,
//autoFormat: false,
//autoHideDialCode: false,
//autoPlaceholder: false,
//defaultCountry: "auto",
//ipinfoToken: "yolo",
//nationalMode: false,
//numberType: "MOBILE",
//onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
//preferredCountries: ['cn', 'jp'],
//preventInvalidNumbers: true,
utilsScript: "lib/libphonenumber/build/utils.js"
});
</script>
Here is the link where I am trying to implement it: https://www.easyac./mobile/verifynumber.html
I have tried changing the mented out options in script but it doesn't help.
Share Improve this question asked Mar 5, 2015 at 16:34 Abhishek SinghAbhishek Singh 1971 gold badge4 silver badges18 bronze badges 07 Answers
Reset to default 6Ok I solved this problem.
So basically here are the option fields that must be true and we need to place the below script before </head>
tag.
Script:
<script>
$(function() {
$("#mobile-number").intlTelInput({
allowExtensions: true,
autoFormat: false,
autoHideDialCode: false,
autoPlaceholder: false,
defaultCountry: "auto",
ipinfoToken: "yolo",
nationalMode: false,
numberType: "MOBILE",
//onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
//preferredCountries: ['cn', 'jp'],
preventInvalidNumbers: true,
utilsScript: "lib/libphonenumber/build/utils.js"
});
});
</script>
Place it before closing head tag and remember to call $("#mobile-number").intlTelInput();
as it is important.
You just forget to put your jquery code inside de document.ready.
see below:
$(document).ready(function(){
$("#mobile-number").intlTelInput({
//allowExtensions: true,
//autoFormat: false,
//autoHideDialCode: false,
//autoPlaceholder: false,
//defaultCountry: "auto",
//ipinfoToken: "yolo",
//nationalMode: false,
//numberType: "MOBILE",
//onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
//preferredCountries: ['cn', 'jp'],
//preventInvalidNumbers: true,
utilsScript: "lib/libphonenumber/build/utils.js"
});
});
Country code will always be in input field with this code
$("#mobile-number").on("blur keyup change", function() {
if($(this).val() == '') {
var getCode = $("#mobile-number").intlTelInput('getSelectedCountryData').dialCode;
$(this).val('+'+getCode);
}});
$(document).on("click",".country",function(){
if($("#phone").val() == '') {
var getCode = $("#mobile-number").intlTelInput('getSelectedCountryData').dialCode;
$("#mobile-number").val('+'+getCode);
}});
$(function() {
$("#mobile-number").intlTelInput({
autoHideDialCode: false,
autoPlaceholder: false,
nationalMode: false
});
});
Why country flag and country code are not stable on page post back.
Here is what I have tried so far:
<script>
$(document).ready(function () {
$("#Phone").intlTelInput({
allowDropdown: true,
// autoHideDialCode: false,
// autoPlaceholder: "off",
// dropdownContainer: "body",
// excludeCountries: ["us"],
defaultCountry: "auto",
// formatOnDisplay: false,
//geoIpLookup: function (callback) {
// $.get("http://ipinfo.io", function () { }, "jsonp").always(function (resp) {
// var countryCode = (resp && resp.country) ? resp.country : "";
// callback(countryCode);
// });
//},
//initialCountry: "auto",
// nationalMode: false,
// onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
// placeholderNumberType: "MOBILE",
// preferredCountries: ['in','pk', 'np','bd', 'us','bt','sg','lk','ny','jp','hk','cn'],
// separateDialCode: true,
utilsScript: "build/js/utils.js"
});
$("#Phone").on("countrychange", function (e, countryData) {
$("#hdnPhone").val(countryData.dialCode);
});
});
</script>
<script>
$(document).ready(function () {
$("#Phone").val('');
var HdnVal = $("#hdnPhone").val();
if (HdnVal != '') {
var countryData = $("#Phone").intlTelInput("getSelectedCountryData");
$("#hdnPhone").val(countryData.dialCode);
}
});
</script>
try this code
$("#mobile-number").intlTelInput({
// allowExtensions: true,
//autoFormat: false,
autoHideDialCode: false,
// autoPlaceholder: false,
// defaultCountry: "auto",
//ipinfoToken: "yolo",
nationalMode: false,
// numberType: "MOBILE",
// onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
//preferredCountries: ['cn', 'jp'],
//preventInvalidNumbers: true,
utilsScript: "lib/libphonenumber/build/utils.js"
});
});
//if you want to get coutry code value in input box then set false
nationalMode: false,
separateDialCode: false,
Pease set this two lines in your function property it will run