简体   繁体   中英

How to trigger a function when this select box changed?

<?php echo Form::select('order_item[quantity][]', $order_item->quantity,   
Util_Model::get_prop($order_item, 'item_sku', 'item', 'get_sales_restriction()') 
, array('class' => 'select-block check_quantity')); ?>

I have such a selectbox and the following code not work.

$(".check_quantity").change(function(){
    alert('come in');
    $.skus_check();
});
$.skus_check = function(){
    var item_skus_quantities = [];
    $('.check_quantity').each(function(){
        item_skus_quantities.push($(this).val());
    });
}

I want to get all the select values into an array.How to do it,thanks

<button class="btn dropdown-toggle clearfix btn-input" data-toggle="dropdown" 
 id="form_order_item[quantity][]"><span class="filter-option pull-left">1</span>    
&nbsp;<span class="caret"></span></button>

in fact the problem is because the bootstrap. in this span filter-option pull-left is the selected value. How to deal with this?

Try this

 <script>
 $(function(){

    $(".check_quantity").on("change",function(){
      alert('come in');
     var ret= getChecked();
     });
 });

 function getChecked(){
  var items = [];
    $.each($('.check_quantity:checked'),function(){
     items.push($(this).val())
    });
   return items;
  }
 </script>

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