Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda