Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
423
WebDropDown select values and checkboxes in javascript
posted

Here is a routine to select set items and their check/uncheck checkboxes in Javascript.

Hope it helps someone like me who spent some good time trying to figure out why this wasn't as easy as in code behind.

I am sure there are more approaches, but this sub will get you started.

function SetValuesCountryofSales(paramitemstomark) {
            var witemstomark = paramitemstomark.split("~")
            var items = _WebDropDown.get_items();   /* Initilized before */
            var i = 0;
            var item = '';
            for (i = 0; i <= items.getLength() - 1; i++) {  /* Loops through the whole cbo */
                item = items.getItem(i);
                item.unselect();    /* this is if there where selected items */
                item.get_element().childNodes[0].checked = false; /* this is if there where selected checked */

                for (j = 0; j <= witemstomark.length - 1; j++) {
                    if (item.get_value() == witemstomark[j]) {
                        item.select();
                        item.get_element().childNodes[0].checked = true;
                    }
                }
            }
        }

 

Good luck,

Federico.