mardi 2 mai 2017

mvc razor view checkbox change event listbox select all not working

I am working on a mvc 4 application which has a checkbox and listbox in cshtml page. when user check the checkbox I am running change event and making attribute property select as select for all items in listbox and unselecting on uncheck. Every thing is working fine until user repeat same process, I mean re checking the checkbox not selecting the items in listbox.

Here is my code, could you please provide your inputs on fixing this issue.

<script type="text/javascript">
    $(document).ready(function () {
        $('#chkitems').change(function () {
            debugger;
            if ($(this).is(':checked')) {
                $('#files').each(function () {
                    $("#files option").attr("selected", "selected");
                });
            }
            else {
                $('#files').each(function () {
                    $("#files option").attr("selected", false);
                });
            }

        });
        });
  </script>




Aucun commentaire:

Enregistrer un commentaire