javascript - Refresh a select tag to default value -
i have 2 select tag. want refresh values in 2nd select tag default , when user click on first select tag. how achieve in javascript
you need use onchange
event perform task. idea when first select changed, set default value (here choose set first item of list, can whatever need re-initialize value).
function initialize() { var select_car = document.getelementbyid("select_car"); var select_power = document.getelementbyid("select_power"); select_car.selectedindex = 0; select_power.selectedindex = 0; select_car.addeventlistener("change", function() { select_power.selectedindex = 1; }); }
<body onload="initialize()"> <select id="select_car"> <option disabled>-- select car --</option> <option>mazda mx5</option> <option>nissan skyline gtr</option> </select> <select id="select_power"> <option disabled>-- select power --</option> <option>150cv</option> <option>255cv</option> </select> </body>
Comments
Post a Comment