File: /var/www/quadcode-jobs/node_modules/intl-tel-input/examples/gen/country-sync.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example: Country sync</title>
<link rel="stylesheet" href="../css/prism.css">
<link rel="stylesheet" href="../../build/css/intlTelInput.css?1638200991544">
<link rel="stylesheet" href="../../build/css/demo.css?1638200991544">
<link rel="stylesheet" href="../css/countrySync.css?1638200991544">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-N472J4QKC4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-N472J4QKC4');
</script>
</head>
<body>
<a href="/">Back</a>
<h1>Example: Country sync</h1>
<p>Use static getCountryData method to create a separate country dropdown for an address form, and then listen for change events to keep the two dropdowns in sync.</p>
<h2>Markup</h2>
<pre><code class="language-markup"><div class="form-item">
<label>Telephone number</label>
<input id="phone" type="tel">
</div>
<div class="form-item">
<label>Address</label>
<input type="text" placeholder="House name/number">
<input type="text" placeholder="City">
<input type="text" placeholder="State">
<input type="text" placeholder="Zip code">
<select id="address-country"></select>
</div></code></pre>
<h2>Code</h2>
<pre><code class="language-javascript">// get the country data from the plugin
var countryData = window.intlTelInputGlobals.getCountryData(),
input = document.querySelector("#phone"),
addressDropdown = document.querySelector("#address-country");
// init plugin
var iti = window.intlTelInput(input, {
utilsScript: "../../build/js/utils.js?1638200991544" // just for formatting/placeholders etc
});
// populate the country dropdown
for (var i = 0; i < countryData.length; i++) {
var country = countryData[i];
var optionNode = document.createElement("option");
optionNode.value = country.iso2;
var textNode = document.createTextNode(country.name);
optionNode.appendChild(textNode);
addressDropdown.appendChild(optionNode);
}
// set it's initial value
addressDropdown.value = iti.getSelectedCountryData().iso2;
// listen to the telephone input for changes
input.addEventListener('countrychange', function(e) {
addressDropdown.value = iti.getSelectedCountryData().iso2;
});
// listen to the address dropdown for changes
addressDropdown.addEventListener('change', function() {
iti.setCountry(this.value);
});
</code></pre>
<h2>Result</h2>
<div id="result">
<div class="form-item">
<label>Telephone number</label>
<input id="phone" type="tel">
</div>
<div class="form-item">
<label>Address</label>
<input type="text" placeholder="House name/number">
<input type="text" placeholder="City">
<input type="text" placeholder="State">
<input type="text" placeholder="Zip code">
<select id="address-country"></select>
</div>
</div>
<script src="../js/prism.js"></script>
<script src="../../build/js/intlTelInput.js?1638200991544"></script>
<script src="./js/countrySync.js?1638200991544"></script>
</body>
</html>