How to append multiple values to a single parameter in html form?

后端 未结 4 1192
迷失自我
迷失自我 2021-01-12 03:48

Assuming I have the following form:

Oats
4条回答
  •  一个人的身影
    2021-01-12 04:11

    I was really only interested in checkboxes that were actually checked - so I built myfunc() from the other examples like this:

    function myfunc(){
        $('#void input[type="checkbox"]').each(function(id,elem){
            if ( ! $(this).is(':checked') ) return;
            b = $("#res").val();
            if(b.length > 0){
                $("#res").val( b + ',' + $(this).val() );
            } else {
                $("#res").val( $(this).val() );
            }
        });
        var stuff = $("#res").val();
        if ( stuff.length < 1 ) {
            alert('Please select at least one');
        } else {
            $("#real").submit();
        }
    }
    

提交回复
热议问题