How to change Option one value to selected after a click event or after an onClick function

I am Using this code to change the option value but it doesn't work !

JavaScript

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script type="text/javascript">
       function changeDefaultSelection(){
           $("#selectVehicle").val('1');
       }
    </script>

HTML

<html>
   <select id="selectVehicle">
      <option  value="0"> Please Select A Vehicle </option>
      <option  value="1"> Car </option>
      <option  value="2"> Bus </option>
   </select>
<button onclick="changeDefaultSelection()"> Change me</button>
</html>

Answers 1

Related Articles