Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!