Search code examples
javascriptdrop-down-menulistfield

Javascript - How to make auto select another drop down


  • Here have two list field menu. First brand second item
  • I want if we select brand IBM that item will select IBM too
  • In other hand, if we select brand HP that item will select HP too

How to do that in javascript.

<select name="brand">
  <option>Please Select</option>
  <option>IBM</option>
  <option>HP</option>
</select>

<select name="item">
  <option>Please Select</option>
  <option>IBM</option>
  <option>HP</option>  
</select>

Solution

  •  <select name="brand" id="brand" onchange="document.getElementById('item').value = document.getElementById('brand').value">
       <option>Please Select</option>
       <option>IBM</option>
       <option>HP</option>
     </select>
    
     <select name="item" id="item">
       <option>Please Select</option>
       <option>IBM</option>
       <option>HP</option>  
     </select>