We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Check/ Unchek in Listbox

Hello,

how can i check or uncheck a checkbox in a Listbox programmaticly with javascript?
I have a Ajax Post Method. If a user select a Listbox checkbox, it is getting automaticly checked/unchecked. But if there is an Error in the Post-Method i want to undo the check/uncheck.

Thanks

1 Reply

SS Selvamani Sankarappan Syncfusion Team November 29, 2016 12:00 PM UTC

Hi Arthur,   
Thanks for using Syncfusion products.   
We can check and uncheck the list items of the ListBox component in AJAX success using our existing methods uncheckItemsByIndices and checkItemsByIndices. Please refer to the following code example:   
  
[script]   
function click(e) {   
        $.ajax({   
   
            url: "ListBox/listbox",   
   
            type: 'POST',   
   
            dataType: "json",   
   
            success: function (result) {   
                var obj = $('#listboxsample').data("ejListBox");   
                var checkedindices = obj.model.checkItemsByIndex; //get the checked          items   
                obj.uncheckItemsByIndices(checkedindices); //unchecked items   
   
               // obj.checkItemsByIndices("2,3"); // check the items   
            }   
        });   
   
    }   
  
   
Refer to the following sample:   
   
In above sample, we have unchecked the list items that are checked in AJAX success.   
To know more about the list of properties, methods, and events available in ListBox component, please refer to the following link: https://help.syncfusion.com/api/js/ejlistbox#methods:checkitemsbyindices   
   
Regards,   
Selvamani S.  

Loader.
Live Chat Icon For mobile
Up arrow icon