+ 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

9th Aug 2021, 7:39 AM
GOLLAKOTI VENKATA SAI SIVA MANI CHANDU
GOLLAKOTI VENKATA SAI SIVA MANI CHANDU - avatar
4 Answers
9th Aug 2021, 10:59 AM
JaScript
JaScript - avatar
+ 1
I appreciate your answer you help me but I want users location to be selected automatically
9th Aug 2021, 9:24 AM
GOLLAKOTI VENKATA SAI SIVA MANI CHANDU
GOLLAKOTI VENKATA SAI SIVA MANI CHANDU - avatar
+ 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()
9th Aug 2021, 10:48 AM
Pariket Thakur
Pariket Thakur - avatar
0
Chandu Gollakoti for that u can use api to get user location
9th Aug 2021, 10:34 AM
Pariket Thakur
Pariket Thakur - avatar