Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Drop down default current country

Drop down default current country 2 years 8 months ago #101301

  • emimarz
  • emimarz's Avatar
  • Offline
  • Junior Lime
  • Posts: 31
  • Thank you received: 5
  • Karma: 1
Well, the title explain all. I need do a drop down and put as default the current country.

Is it possible?

thanks in advance
Emiliano
The administrator has disabled public write access.

Drop down default current country 2 years 8 months ago #101364

  • emimarz
  • emimarz's Avatar
  • Offline
  • Junior Lime
  • Posts: 31
  • Thank you received: 5
  • Karma: 1
Ready I do it.

There is the solution if somebody need it

on template survey I add a input and the following JS
<input id="country-code" type="hidden" />
<script>
    $(document).ready(function(){
      if($("#idoftheselect").length==1){
        jQuery.getJSON('http://freegeoip.net/json/', function(location) {
          $('#country-code').val(location.country_code);
          $("#idoftheselect [value="+location.country_code+"]").attr("selected", true);
        });
      }
    });
  </script>

The drop down will need the next format
id = code 2 characters following the iso 3166-1
here you have a reference
en.wikipedia.org/ISO_3166-1

I hope be helpful
if somebody need help please answer to this topic

Best
Emiliano
Last Edit: 2 years 8 months ago by DenisChenu. Reason: code
The administrator has disabled public write access.
The following user(s) said Thank You: DenisChenu, tpartner, Ben_V

Drop down default current country 2 years 8 months ago #101381

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9254
  • Thank you received: 1319
  • Karma: 382
Hi,

Thanks, it's a great information here !

Maybe a good system for
- WorkAround on wiki
- New attribute and/or question type dor 2.1 LS release
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.219 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form