Send multiple <select> elements with jQuery POST

后端 未结 2 1754
北海茫月
北海茫月 2021-01-06 23:34

I have this jQuery code to add

提交评论

  • 2021-01-07 00:13

    First of all you have to use classes for your selects instead of an id. jQuery will only return one element when you use an id. After that the following function will convert all values of the selects you give as paramater as an array.

    /**
     * Convert select to array with values
     */    
    function serealizeSelects (select)
    {
        var array = [];
        select.each(function(){ array.push($(this).val()) });
        return array;
    }
    

    So:

    var course_ids = serealizeSelects($('.course_id'));
    

    Should for example return:

    [1,3,2]
    
    0 讨论(0)
  • 提交回复
    热议问题