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

103
Vistas
Change Image with Multiple Options

I am creating a rabbit genetics calculator in sorts that allows the user to put a genetic string with select options. Depending on the genes selected, it will show an image of what the color should look like. The main three genes need to change the base color image, and marking images depending on the genes selected.

<div class="rabbit">
    <img id="basecoat" src="img/base/chestnut.png" border="0">
    <img id="tort" src="img/tort/tort.png" border="0">
</div>

<select id="agouti">
    <option value="chestnut" selected>chestnut</option>
    <option value="self">self</option>
</select>

<select id="extension">
    <option value="black" selected>black</option>
    <option value="red">red</option>
</select>

<select id="color">
    <option value="full" selected>full</option>
    <option value="chin">chinchilla</option>
</select>

Here are the combos and their desired effect:

"chestnut" + "black" + "full" = img/base/chestnut.png
"chestnut" + "black" + "chin" = img/base/chinchilla.png
"chestnut" + "red" + "full" = img/base/orange.png
"chestnut" + "red" + "chin" = img/base/frosty.png
"self" + "black" + "full" = img/base/black.png
"self" + "black" + "chin" = img/base/black.png
"self" + "red" + "full" = img/base/black.png + img/tort/tort.png
"self" + "red" + "chin" = img/base/black.png + img/tort/sallander.png
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You'll need to prepare a noimage.png file to use it as a placeholder in case of error or when the second image is not supposed to show up.

Try this code.

var $tag = $("#agouti").val () + "_" + $("#extension").val () + "_" + $("#color").val ();

var combos = {"chestnut_black_full":['img/base/chestnut.png', 'noimage.png'],
"chestnut_black_chin":['img/base/chinchilla.png', 'noimage.png'],
"chestnut_red_full":['img/base/orange.png', 'noimage.png'],
"chestnut_red_chin":['img/base/frosty.png', 'noimage.png'],
"self_black_full":['img/base/black.png', 'noimage.png'],
"self_black_chin":['img/base/black.png', 'noimage.png'],
"self_red_full":['img/base/black.png', 'img/tort/tort.png'],
"self_red_chin":['img/base/black.png', 'img/tort/sallander.png']};

$(document).on ("change", "select", function () {
   if (combos[$tag]) {
      $("#basecoat").attr ("src", combos[$tag][0]);
      $("#tort").attr ("src", combos[$tag][1]);
   }
   else {
     $("$basecoat, $tort").attr ("src", "noimage.png");
   }
});
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