Answers for "<select> in html"

20

select html

<select class="form-control">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
</select>
Posted by: Guest on July-30-2020
0

select html

<select id="car" onchange="ChangeCarList()"> 
  <option value="">-- Car --</option> 
  <option value="VO">Volvo</option> 
  <option value="VW">Volkswagen</option> 
  <option value="BMW">BMW</option> 
</select> 

<select id="carmodel"></select> 

let carsAndModels = {};
carsAndModels['VO'] = ['V70', 'XC60', 'XC90'];
carsAndModels['VW'] = ['Golf', 'Polo', 'Scirocco', 'Touareg'];
carsAndModels['BMW'] = ['M6', 'X5', 'Z3'];

function ChangeCarList() {
  let selCar = car.options[car.selectedIndex].value;
  while (carmodel.options.length) {
    carmodel.remove(0);
  }
  
  let cars = carsAndModels[selCar];
  if (cars) {
    var i;
    for (i = 0; i < cars.length; i++) {
      let car = new Option(cars[i], i);
      carmodel.options.add(car);
    }
  }
}
Posted by: Guest on May-05-2022

Browse Popular Code Answers by Language