Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
Multiple buttons with different ID's to one Variable

So im trying to make different languages for a user terminal. The way you select one is by clicking on an image with the corresponding country flag, which changes the language to the national language of the country. My thoughts on how to do that would be that upon click, the button would change the value of a variable which in change would alter the displayed language. My first thought on how to implement that would be with switch case, but i really just dont know how to program it.

This is what i got so far, but when i tried it with alert, it didnt work:

var languages = "";
        $('#UK, #FR, #SP, #HU, #IN, #CH, #JA, #SK, #BU').click(function() {
            switch(languages){
                case "#UK":languages = 'UK';break;
                case "FR":languages = 'FR';break;
                case "SP":languages = 'SP';break;
                case "HU":languages = 'HU';break;
                case "IN":languages = 'IN';break;
                case "CH":languages = 'CH';break;
                case "JA":languages = 'JP';break;
                case "SK":languages = 'SK';break;
                case "BU":languages = 'BU';break;
            }
        })

I, in theory could also just make the same followup page 10x and let the buttons load those pages, but i wouldnt be satisfied with that. Also im sorry if this is a stupid question, im still very new to js.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The id of your clicked element seems to exactly match the language you want to set, so simply do that.

let languages = "";
        
$('#UK, #FR, #SP, #HU, #IN, #CH, #JA, #SK, #BU').on('click', function() {
    languages = this.id;
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda