Help with the onchange function

0

I'm trying to use the onchange function, until I get the value, but I can not make use of the value,

Select and script:

<select id="mySelect" onchange="myFunction()">
  <option value="1">1 Questão
  <option value="2">2 Questões
  <option value="3">3 Questões
  <option value="4">4 Questões
</select>
</div>

<b id="demo"></b> //aqui eu imprimo o valor de x corretamente

<script>
function myFunction() {
    var x = document.getElementById("mySelect").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

I would like to use the value of X as a complement to the image address

I tried this way:

  <img src="img/gab<?echo '<b id="demo"></b>'?>.png" />

So

  <img src="img/gab<script>x</script>.png" />

and

  <img src="img/gab<script>$x</script>.png" />

I do not know how to do it

    
asked by anonymous 24.09.2018 / 21:10

1 answer

2

Try to do this:

function myFunction() {
    var x = document.getElementById("mySelect").value;
    document.getElementById("demo").innerHTML = x;
    document.getElementById("imagem").src = "img/gab" + x + ".png"
}
<select id="mySelect" onchange="myFunction()">
  <option value="1">1 Questão
  <option value="2">2 Questões
  <option value="3">3 Questões
  <option value="4">4 Questões
</select>

<b id="demo"></b>

<img id="imagem">
    
24.09.2018 / 21:19