Value of jQuery generated checkbox in IE8 is stored as “on” rather than actual value?

后端 未结 3 1251
北恋
北恋 2021-01-23 03:41

The following example code works in FireFox but IE is causing problems.

This code essentially renders a list of dynamic checkboxes according to a JSON array.

Whe

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-23 04:38

    I found a solution for anyone whom is interested. It's more of a work around as I couldn't figure out why it was happening.

    On creating each input element instead of popuating the value field which just gets set to 'on' in IE when using jquery 1.4. I created a val attr for each element and store the category id. Then I simply call this code on submit to harvest the results.

    $(document).ready(function() {
            $("form").submit(function(){
    
                var str = "";
                    $("#ProfSelector input:checkbox:checked").each(function () {
                        str += $(this).attr("val") + ",";
                    });
    
                $("form").append( $("").attr({ "type":"text", "name":"selectedCategories", "value":str }));
            });
        });
    

提交回复
热议问题