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

Listbox with checkbox select event

I'm trying to exec javascript function on list item checked/unchecked.
I have listbox in my view:

@Html.EJ().ListBox("lstCam").Height("200").Datasource((IEnumerable<CaptureSources>)ViewBag.dsCam).ListBoxFields(df => df.Text("name")).ShowCheckbox(true).ClientSideEvents(e => e.Select("onSelect"))

The function is like this:

<script type="text/javascript">
    function onSelect(args) {
        var target;
        target = $('#lstCam').data("ejListBox");
        var checkedItems = target.getCheckedItems();
        var sel;
        if (checkedItems.length) {
            $(checkedItems).each(function (index, ele) {
                sel += ele.value + ",";
            });
            
        }
    }
</script>

When I run the project, checkboxes in the listbox is looking like filled boxes, instead of checkmarks in empty box. This is something wrong?
And my other problem is when I select one item, the js function is not called.

Maybe a little help?
Thanks!


1 Reply

PP Prasanth Palani Syncfusion Team November 3, 2016 06:49 AM UTC

Hi Bernard,   
   
Thanks for contacting Syncfusion Support.   
   
 Query: when I select one item, the JS function is not called.    
   
If we enable the checkbox, only the checkChange event will be triggered instead of select/change event in the ListBox control. The select and change events are triggered only when the ListBox is rendered without the checkbox.      
   
Query: When I run the project, checkboxes in the listbox is looking like filled boxes, instead of checkmarks in empty box?      
   
We were unable to reproduce the above issue. When we ran the project, checkmarks in the checkboxes rendered properly in the ListBox control. Please ensure that you have referred dependent scripts and CSS files in your application. For you reference, we have prepared a simple ListBox MVC application with checkbox enabled. You can get that sample from:   
 
Sample location: Sample   
   
If the problem persists still, please modify the provided sample based on your application along with the replication procedure to showcase the issue. Or, you can share the code sample of how you had created the ListBox with checkbox and share the console errors, if any. This would help us to provide an appropriate solution at the earliest. 
 
Regards, 
Prasanth P 


Loader.
Up arrow icon