Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
Display the selected content of a combo box in HTML

So, I have a combo box made in HTMl.

https://i.stack.imgur.com/5W6kt.png

HTML Code:

<div>
    <select name="cars" id="cars">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>
</div>

Now, what I need to do is, assign an ID to the <div> tag and define an event to the combo box that will call a function in JS code. This function needs to check the selected value of the <div> (combo box) and write it out in inner HTML, like this:

https://i.stack.imgur.com/Fxbv0.png

I know this is probably an easy job but I'm a beginner, don't go hard on me :D.

Edit: SOLVED!

HTML:

<!doctype html>
<html>
<head>
    <script type="text/javascript" src="script.js"></script>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
  <select id="box1" onChange="function1(this);">
    <option value="">Volvo</option>
    <option value="">Fiat</option>
    <option value="">Seat</option>
    <option value="">Audi</option>  
  </select>
<div  id="div1"></div>
</body>
</html>

JS:

function function1(element) {
    var text = element.options[element.selectedIndex].text;
    document.getElementById("div1").innerHTML = "Selection is: " + text;
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Every Element in HTML has an id is a variable in JS

cars.onchange = function(e){
   car.innerText = cars[cars.selectedIndex].value;
}
<select name="cars" id="cars">
  <option value="">Select a Car</option>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select> selection is: <span id='car'></span>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda