Get values from multiple select boxes with same name? Including its value with jquery and php

前端 未结 4 1285
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 11:36

I have looked for answers on here and have not found anything that directly can help me so I am going to ask here. I have a form with multiple select boxes:

         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-19 12:00

    $(function () {
        var $select = $('select');
        $select.on('change', function () {
            var output = 0;
            for (var i = 0, len = $select.length; i < len; i++) {
                output += parseInt($select.eq(i).val());
            }
            //the `output` variable now contains the addition of all the values from the `acabados[]` select elements
        });
    });
    

    Here is a demo: http://jsfiddle.net/aPXXA/1/

    You can change var $select = $('select'); to var $select = $('[name="acabados[]"]'); to only select the select elements with the acabados[] name attribute.

提交回复
热议问题