how to Select All / Deselect All options in multiple select box using java script?

It’s as follows :

 

function listbox_selectall(listID, isSelect) {
        var listbox = document.getElementById(listID);
        for(var count=0; count < listbox.options.length; count++) {
            listbox.options[count].selected = isSelect;
    }
}

 

onclick="listbox_selectall('countryList', true)" //select all the options

(or)

onclick="listbox_selectall('countryList', false)" //deselect all the options