0

I've used this code on the page and it doesn't work in the browsers I've tried it on. Can you help me correct the error?

<label>Elija un sabor de nieve:
    <select class="nieve" name="nieve">
        <option value="">Seleccione Uno …</option>
        <option value="1">Chocolate</option>
        <option value="2">Sardina</option>
        <option value="3">Vainilla</option>
    </select>
</label>

<div class="resultado"></div>
<script>

const selectElement = document.querySelector('.nieve');
selectElement.addEventListener('change',(event) => {
    const resultado = document.querySelector('.resultado');
    resultado.textContent = 'Te gusta el sabor ${event.target.value';
    });
</script>

This line show an error: "selectElement.addEventListener('change',(event) => {". When selecting an item from the dropdown, it should specify the selected item in text.In Dreamweaver it shows an error on the indicated lines and in Firefox it shows "Do you like the flavor ${event.target.value}".

vimuth
  • 5,064
  • 33
  • 79
  • 116
  • Where is the element that has the `resultado` class? – Mina Jul 15 '22 at 06:38
  • you are using the template literal format to compose the string with the selected option value. Did you use the backticks (`) instead of the single quotes to wrap the string? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals – Diego D Jul 15 '22 at 06:39

1 Answers1

-1

const selectElement = document.querySelector('.nieve');
selectElement.addEventListener('change',(event) => { 
    const resultado = document.querySelector('.resultado'); 
  resultado.textContent = `Te gusta el sabor ${event.target.value}`;
});
<label>Elija un sabor de nieve:
<select class="nieve" name="nieve">
    <option value="">Seleccione Uno …</option>
    <option value="1">Chocolate</option>
    <option value="2">Sardina</option>
    <option value="3">Vainilla</option>
</select>
<div class="resultado"></div>
Sakil
  • 666
  • 3
  • 8
  • Thank you for your answers. I still get the error in Dreamweaver, although the backtick (`) characters solve the second problem. I'll try to update the app or see if Adobe has released anything specific. Thanks again – Mari Carmen De Francisco Jul 15 '22 at 10:03