Javascript Form How to - Reset a select element








Question

We would like to know how to reset a select element.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!--from  w w w  . j a v  a2  s . c o  m-->
    selectElement.options[2].selected="selected";
}
</script>
</head>
<body>
  <select id="selectElement">
    <option>First</option>
    <option selected>Second</option>
    <option>3</option>
    <option>4</option>
  </select>
</body>
</html>

The code above is rendered as follows: