Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Created January 5, 2015 12:54
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save GaryJones/4353a9a78a3495056523 to your computer and use it in GitHub Desktop.
Save GaryJones/4353a9a78a3495056523 to your computer and use it in GitHub Desktop.
Gravity Forms Countries dropdown with country codes
var countryCodes = {
'Afghanistan': '93',
'Albania': '355',
'Algeria': '213',
'American Samoa': '684',
'Andorra': '376',
'Angola': '244',
'Antigua and Barbuda': '1-268',
'Argentina': '54',
'Armenia': '374',
'Australia': '61',
'Austria': '43',
'Azerbaijan': '994',
'Bahamas': '1-242',
'Bahrain': '973',
'Bangladesh': '880',
'Barbados': '1-246',
'Belarus': '375',
'Belgium': '32',
'Belize': '501',
'Benin': '229',
'Bermuda': '10441',
'Bhutan': '975',
'Bolivia': '591',
'Bosnia and Herzegovina': '387',
'Botswana': '267',
'Brazil': '55',
'Brunei': '673',
'Bulgaria': '359',
'Burkina Faso': '226',
'Burundi': '257',
'Cambodia': '855',
'Cameroon': '237',
'Canada': '1',
'Cape Verde': '238',
'Cayman Islands': '1-345',
'Central African Republic': '236',
'Chad': '235',
'Chile': '56',
'China': '86',
'Colombia': '57',
'Comoros': '269',
'Congo, Democratic Republic of the': '243',
'Congo, Republic of the': '242',
'Costa Rica': '506',
'Côte d\'Ivoire': '225',
'Croatia': '385',
'Cuba': '53',
'Cyprus': '357',
'Czech Republic': '420',
'Denmark': '45',
'Djibouti': '253',
'Dominica': '1-767',
'Dominican Republic': '1-809',
'East Timor': '670',
'Ecuador': '593',
'Egypt': '20',
'El Salvador': '503',
'Equatorial Guinea': '240',
'Eritrea': '291',
'Estonia': '372',
'Ethiopia': '251',
'Fiji': '679',
'Finland': '358',
'France': '33',
'French Polynesia': '689',
'Gabon': '241',
'Gambia': '220',
'Georgia': '995',
'Germany': '49',
'Ghana': '233',
'Greece': '30',
'Greenland': '299',
'Grenada': '1-473',
'Guam': '1-671',
'Guatemala': '502',
'Guinea': '224',
'Guinea-Bissau': '245',
'Guyana': '592',
'Haiti': '509',
'Honduras': '504',
'Hong Kong': '852',
'Hungary': '36',
'Iceland': '354',
'India': '91',
'Indonesia': '62',
'Iran': '98',
'Iraq': '964',
'Ireland': '353',
'Israel': '972',
'Italy': '39',
'Jamaica': '1-876',
'Japan': '81',
'Jordan': '962',
'Kazakhstan': '7',
'Kenya': '254',
'Kiribati': '686',
'North Korea': '850',
'South Korea': '82',
'Kosovo': '381',
'Kuwait': '965',
'Kyrgyzstan': '996',
'Laos': '856',
'Latvia': '371',
'Lebanon': '961',
'Lesotho': '266',
'Liberia': '231',
'Libya': '218',
'Liechtenstein': '423',
'Lithuania': '370',
'Luxembourg': '352',
'Macedonia': '389',
'Madagascar': '261',
'Malawi': '265',
'Malaysia': '60',
'Maldives': '960',
'Mali': '223',
'Malta': '356',
'Marshall Islands': '692',
'Mauritania': '222',
'Mauritius': '230',
'Mexico': '52',
'Micronesia': '691',
'Moldova': '373',
'Monaco': '377',
'Mongolia': '976',
'Montenegro': '382',
'Morocco': '212',
'Mozambique': '258',
'Myanmar': '95',
'Namibia': '264',
'Nauru': '674',
'Nepal': '977',
'Netherlands': '31',
'New Zealand': '64',
'Nicaragua': '505',
'Niger': '227',
'Nigeria': '234',
'Norway': '47',
'Northern Mariana Islands': '1-670',
'Oman': '968',
'Pakistan': '92',
'Palau': '680',
'Palestine': '970',
'Panama': '507',
'Papua New Guinea': '675',
'Paraguay': '595',
'Peru': '51',
'Philippines': '63',
'Poland': '48',
'Portugal': '351',
'Puerto Rico': '1-939',
'Qatar': '974',
'Romania': '40',
'Russia': '7',
'Rwanda': '250',
'Saint Kitts and Nevis': '1-869',
'Saint Lucia': '1-758',
'Saint Vincent and the Grenadines': '1-784',
'Samoa': '685',
'San Marino': '378',
'Sao Tome and Principe': '239',
'Saudi Arabia': '966',
'Senegal': '221',
'Serbia and Montenegro': '381',
'Seychelles': '248',
'Sierra Leone': '232',
'Singapore': '65',
'Slovakia': '421',
'Slovenia': '386',
'Solomon Islands': '677',
'Somalia': '252',
'South Africa': '27',
'Spain': '34',
'Sri Lanka': '94',
'Sudan': '249',
'Sudan, South': '211',
'Suriname': '597',
'Swaziland': '268',
'Sweden': '46',
'Switzerland': '41',
'Syria': '963',
'Taiwan': '886',
'Tajikistan': '992',
'Tanzania': '255',
'Thailand': '66',
'Togo': '228',
'Tonga': '676',
'Trinidad and Tobago': '1-868',
'Tunisia': '216',
'Turkey': '90',
'Turkmenistan': '993',
'Tuvalu': '688',
'Uganda': '256',
'Ukraine': '380',
'United Arab Emirates': '971',
'United Kingdom': '44',
'United States': '1',
'Uruguay': '598',
'Uzbekistan': '998',
'Vanuatu': '678',
'Vatican City': '379',
'Venezuela': '58',
'Vietnam': '84',
'Virgin Islands, British': '1-284',
'Virgin Islands, U.S.': '1-340',
'Yemen': '967',
'Zambia': '260',
'Zimbabwe': '263'
};
@Lpizarro93
Copy link

How do you install these on gravity forms so that it gives people an option to select the country code?

@jacobedawson
Copy link

If anyone comes across this, I used this list to auto-populate a phone number input when a user selects a country:

        // on document load or something 
        const countrySelects = [].slice.call(
            document.querySelectorAll(".has_country select")
        );
        const telephoneInputs = [].slice.call(
            document.querySelectorAll(".ginput_container_phone input")
        );
        telephoneInputs.forEach(i => {
            i.value = "+1";
        });
        countrySelects.forEach(c => {
            c.addEventListener("change", e => {
                const selectedCountry = e.target.value || "";
                telephoneInputs.forEach(t => {
                    t.value = `+${countryCodes[selectedCountry]}`;
                });
            });
        });
       // other code

I had multiple forms on the page hence using array syntax rather than a single querySelector (in which case you don't need to loop).

@upsparkdev
Copy link

How do you install these on gravity forms so that it gives people an option to select the country code?

You need to upload via the 'bulk add/ predefined choices' button. Use this version:

Afghanistan|+93
Albania|+355
Algeria|+213
American Samoa|+684
Andorra|+376
Angola|+244
Antigua and Barbuda|+1-268
Argentina|+54
Armenia|+374
Australia|+61
Austria|+43
Azerbaijan|+994
Bahamas|+1-242
Bahrain|+973
Bangladesh|+880
Barbados|+1-246
Belarus|+375
Belgium|+32
Belize|+501
Benin|+229
Bermuda|+10441
Bhutan|+975
Bolivia|+591
Bosnia and Herzegovina|+387
Botswana|+267
Brazil|+55
Brunei|+673
Bulgaria|+359
Burkina Faso|+226
Burundi|+257
Cambodia|+855
Cameroon|+237
Canada|+1
Cape Verde|+238
Cayman Islands|+1-345
Central African Republic|+236
Chad|+235
Chile|+56
China|+86
Colombia|+57
Comoros|+269
Congo, Democratic Republic of the|+243
Congo, Republic of the|+242
Costa Rica|+506
Côte d'Ivoire|+225
Croatia|+385
Cuba|+53
Cyprus|+357
Czech Republic|+420
Denmark|+45
Djibouti|+253
Dominica|+1-767
Dominican Republic|+1-809
East Timor|+670
Ecuador|+593
Egypt|+20
El Salvador|+503
Equatorial Guinea|+240
Eritrea|+291
Estonia|+372
Ethiopia|+251
Fiji|+679
Finland|+358
France|+33
French Polynesia|+689
Gabon|+241
Gambia|+220
Georgia|+995
Germany|+49
Ghana|+233
Greece|+30
Greenland|+299
Grenada|+1-473
Guam|+1-671
Guatemala|+502
Guinea|+224
Guinea-Bissau|+245
Guyana|+592
Haiti|+509
Honduras|+504
Hong Kong|+852
Hungary|+36
Iceland|+354
India|+91
Indonesia|+62
Iran|+98
Iraq|+964
Ireland|+353
Israel|+972
Italy|+39
Jamaica|+1-876
Japan|+81
Jordan|+962
Kazakhstan|+7
Kenya|+254
Kiribati|+686
North Korea|+850
South Korea|+82
Kosovo|+381
Kuwait|+965
Kyrgyzstan|+996
Laos|+856
Latvia|+371
Lebanon|+961
Lesotho|+266
Liberia|+231
Libya|+218
Liechtenstein|+423
Lithuania|+370
Luxembourg|+352
Macedonia|+389
Madagascar|+261
Malawi|+265
Malaysia|+60
Maldives|+960
Mali|+223
Malta|+356
Marshall Islands|+692
Mauritania|+222
Mauritius|+230
Mexico|+52
Micronesia|+691
Moldova|+373
Monaco|+377
Mongolia|+976
Montenegro|+382
Morocco|+212
Mozambique|+258
Myanmar|+95
Namibia|+264
Nauru|+674
Nepal|+977
Netherlands|+31
New Zealand|+64
Nicaragua|+505
Niger|+227
Nigeria|+234
Norway|+47
Northern Mariana Islands|+1-670
Oman|+968
Pakistan|+92
Palau|+680
Palestine|+970
Panama|+507
Papua New Guinea|+675
Paraguay|+595
Peru|+51
Philippines|+63
Poland|+48
Portugal|+351
Puerto Rico|+1-939
Qatar|+974
Romania|+40
Russia|+7
Rwanda|+250
Saint Kitts and Nevis|+1-869
Saint Lucia|+1-758
Saint Vincent and the Grenadines|+1-784
Samoa|+685
San Marino|+378
Sao Tome and Principe|+239
Saudi Arabia|+966
Senegal|+221
Serbia and Montenegro|+381
Seychelles|+248
Sierra Leone|+232
Singapore|+65
Slovakia|+421
Slovenia|+386
Solomon Islands|+677
Somalia|+252
South Africa|+27
Spain|+34
Sri Lanka|+94
Sudan|+249
Sudan, South|+211
Suriname|+597
Swaziland|+268
Sweden|+46
Switzerland|+41
Syria|+963
Taiwan|+886
Tajikistan|+992
Tanzania|+255
Thailand|+66
Togo|+228
Tonga|+676
Trinidad and Tobago|+1-868
Tunisia|+216
Turkey|+90
Turkmenistan|+993
Tuvalu|+688
Uganda|+256
Ukraine|+380
United Arab Emirates|+971
United Kingdom|+44
United States|+1
Uruguay|+598
Uzbekistan|+998
Vanuatu|+678
Vatican City|+379
Venezuela|+58
Vietnam|+84
Virgin Islands, British|+1-284
Virgin Islands, U.S.|+1-340
Yemen|+967
Zambia|+260
Zimbabwe|+263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment