I have searched for an answer for this, but has proven to be a bit tricky…
On my html page I have a dropdown menu with a list of all the countries.
<option value="AF">Afghanistan</option>
<option value="AX">Åland Islands</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
My question is that is there a way to default the selected option according to where the site is visited from? (i.e. If I am visiting the site from South Africa, it would automatically change to South Africa
There are some free services out there that let you make country and ip-based geolocalization from the client-side.
I’ve used the wipmania free JSONP service, it’s really simple to use:
Or if you use a framework that supports JSONP, like jQuery you can:
Check the above snippet running here.