简体   繁体   中英

page load select dropdown box option automatically

<select name="optionSnoInput" class="chosen-select" onchange="goodsViewController.option_price_display(this);">
    <option value="">option</option>
    <option value="104">A</option>
    <option value="105">B</option>
    <option value="106">C</option>
    <option value="107">D</option>
    <option value="108">count</option>
</select>

On the above dropdown, I want last option 'count' is automatically selected because I need counting each product's selling Quantity

but my shop program is counting Quantity as option not product

so I add 'count' option, and use 'display:none' css code..

Please suggest!

Thanks.

You can do it with JQuery this way to:

$(window).on('load', function(){
  $('.chosen-select option:last-child').attr('selected','selected');
})

 $(window).on('load', function(){ $('.chosen-select option:last-child').attr('selected','selected'); })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select name="optionSnoInput" class="chosen-select" onchange="goodsViewController.option_price_display(this);"> <option value="">option</option> <option value="104">A</option> <option value="105">B</option> <option value="106">C</option> <option value="107">D</option> <option value="108">count</option> </select>

Use selected for the default option.

<option value="108" selected>count</option>

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