Auto-select country from dropdown with GEOIP
Posted: December 21, 2017
There are 195 countries in the world and asking your user to select the one they are in from a dropdown can be a pain - especially if they’re on a mobile device. Save them the bother by using a GeoIP service and preselecting their current country based on their IP address. In the unlikely event that the user wants to select a different country they can change it.
ProTip: You should also add
autocomplete="country-name" to the select to take advantage of address autocomplete if the country is different.
This is a simple auto-select country from a dropdown using the free GEOIP DB service and jQuery
Geoip-db service: https://geoip-db.com/
Countries list from: https://github.com/mledoze/countries
Hi Christian, thanks a lot for the demo. Why is it, that all browsers block the script because of an “insecure source”?
Hi Markus - thanks for reporting that. The script was working previously but it looks like something changed with the GeoIP API. I’ll look into it. In the meantime you can follow progress on this here: https://github.com/coliff/geoip-db-country-select/issues/3
I am getting the same error you mentioned in this “https://github.com/coliff/geoip-db-country-select/issues/3”. Please fix the issue asap and let me know about the fix. Thanks in advance.
Note - The script was working previously like a charm.
Hi Utkarsh K and Markus M - the issue seems to be fixed now. I didn’t change anything so it was related to the GeoIP system.
Yeah its working now.
Leave a Comment
Your email address will not be published. Required fields are marked *