Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:21:52+00:00 2026-06-15T09:21:52+00:00

i am building a country selector using a pre-made list I found on google,

  • 0

i am building a country selector using a pre-made list I found on google, and a smart method of pinpointing a flag on a png sprite posted on stackoverflow by roberkules (http://stackoverflow.com/questions/5409780/html-country-list-with-flags).

I’m a beginner, and as much as I understand how each part works, I don’t understand how I can “make” the jQuery read the ISO codes and then apply it to each country. I also added <i></i> to the first country to see if it would at least put the Spanish flag but nothing.

! I am aware there is a similar question, but that one uses manual css coordinates, and i wanted it to work with the method in this JavaScript:

(function($) {
// size = flag size + spacing
var default_size = {
    w: 20,
    h: 15
};

function calcPos(letter, size) {
    return -(letter.toLowerCase().charCodeAt(0) - 97) * size;
}

$.fn.setFlagPosition = function(iso, size) {
    size || (size = default_size);

    return $(this).css('background-position',
        [calcPos(iso[1], size.w), 'px ', calcPos(iso[0], size.h), 'px'].join(''));
};
})(jQuery);

// USAGE:

(function($) {

$(function() {
    // on load:
    $('.country i').setFlagPosition('es');

});

})(jQuery);​

http://jsfiddle.net/3TvWs/ Is where I am now.

Could anyone help, even just a hint?

Edit: Sorry, i realize that i explained this badly. The (flag)Spain is just an example of how the pinpointing works. I actually meant the flags to be inside the dropdown, and not have that spain bubble at all. Sorry for the misunderstanding.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:21:54+00:00Added an answer on June 15, 2026 at 9:21 am

    Set an event handler to listen for the change event on the dropdown menu event and call setFlagPosition in it.

    $('select[name="country"]').on('change', function(){
        $('.country i').setFlagPosition($(this).val())[0].nextSibling.nodeValue = $(':selected', this).text();
    });
    

    http://jsfiddle.net/mowglisanu/3TvWs/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a huge database of IP addresses with their geographic location attached (country,
building a site using PHP and MySQL that needs to store a lot of
I am building an online hotel booking system.... Using php and mysql.... Users can
I'm building a registration form where I have a drop down list for security
I'm building a form with radio buttons. <form id=land name=input method=POST action=test.php> <input type=radio
Is there a way to have a full list of countries without building the
I am building an application that uses GPS to determine users current country. Now,
I'm building a Geocoding class that can utilize multiple webservices for Geocoding (ie Google,
I'm building a site where the user can choose a country, state and city
I am using Google Maps in a project and I want to display only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.