<label id="lblCountry">Country*:</label>
<select class="js-example-basic-single form-control" name="state[]" id="country" class="country" onChange="fnCountryCode(this.value);fnCountry()" >
<option>-Select-</option>
......
</select>
<input type="text" class="form-control" id="txtCode" name="txtCode" placeholder="+61">
function fnCountryCode(strCity)
{
document.getElementById("txtCode").value = "";
if (strCity != 'other') {
var client = new XMLHttpRequest();
client.open("GET", "https://restcountries.eu/rest/v2/alpha/" + strCity, true);
client.send();
client.onreadystatechange = function () {
if (client.readyState == 4 && this.status == 200) {
var arr = JSON.parse(client.responseText);
document.getElementById("txtCode").value = "+" + arr.callingCodes;
//alert(arr.callingCodes);
}
};
}
}