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

173
Vistas
Unable to Choose another Option in Select tags. Always defaults to first option with a value

There are similar questions like this, but I either can't find what I am looking for, or I may be missing something. Here is the code below.

        <select id="colorSelector" onchange="getColor()">
        <option>Choose a color</option>
        <option value="green">Green</option>
        <option value="red">Red</option>
        </select>

JS

function getColor(){
if(document.getElementById('colorSelector').value = "green"){
    document.getElementById('mainButton').setAttribute('onclick', 'colorChangeGreen()')

}else if(document.getElementById('colorSelector').value = "red"){
    document.getElementById('mainButton').setAttribute('onclick', 'colorChangeRed()')
}}

After I open dropdown and choose either of the two colors, it always chooses green and then I can't choose red. I am wondering what I need to edit to be able to choose other colors, I wanted to put a few more options in. Thank you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

 <select id="colorSelector" onchange="getColor()">
    <option>Choose a color</option>
    <option value="green">Green</option>
    <option value="red">Red</option>
    </select>
    <input type="button" id="mainButton" value="color" />  


<script>
function getColor(){
if(document.getElementById('colorSelector').value == "green"){
    document.getElementById('mainButton').setAttribute('onclick', 'colorChangeGreen()')

}else if(document.getElementById('colorSelector').value == "red"){
    document.getElementById('mainButton').setAttribute('onclick', 'colorChangeRed()')
}}
</script>
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