+ 1
Auto detect country and apply it on select tag
I have a select tag where it asks country of user, user can select whatever he wants also it should be filled automatically depending on their location if the location detect is not wanted by user he can select any country from options https://code.sololearn.com/W1pNBYr6yCML/?ref=app
7 odpowiedzi
+ 2
This will you help:
https://code.sololearn.com/W2Rn4VIP0wTR/?ref=app
+ 1
I appreciate your answer you help me but I want users location to be selected automatically
+ 1
function getCode() {
var xmlhttp = new XMLHttpRequest();
var url = "https://ipgeolocation.abstractapi.com/v1/?api_key=1be9a6884abd4c3ea143b59ca317c6b2";
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var data =JSON.parse(this.responseText);
//console.log(this.responseText)
console.log(data.city);
document.querySelector("#ccode").value= data.city
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
//var id = prompt("Enter Your Id ")
getCode()
0
Chandu Gollakoti for that u can use api to get user location