简体   繁体   中英

how to set a default value and populate in drop down select box when page loads in jquery

on document ready, I have given like below code

$(document).ready(function(){
  $('#dropID').val(10);
});

But whenever page loads, the value is not binded in that select box. Can any one suggest?

Setting the value in a standard <select> will select it.

If your select code does not look like this, then that is the issue. Assuming you load jQuery and the IDs are correct

 $(function() { $("#dropID").val(10) })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select id="dropID"> <option value="">Please select</option> <option value="10">Ten</option> <option value="20">Twenty</option> <option value="30">Thirty</option> </select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM