Multi-select box without ctrl-click

I am using the code written in this stackoverflow post

How can I avoid having to ctrl-click on a multiple file selection box using Javascript?

It is also recommended in many other articles to make multiple selections without pressing Ctrl.

code:

$('option').mousedown(function(e) {
    e.preventDefault();
    $(this).prop('selected', !$(this).prop('selected'));
    return false;
});

      

The problem is that the FireFox 31.0 code doesn't work. you can try it using the following link

FIDDLE

does anyone know work around this issue :)

+3


source to share


1 answer


Below code works in firefox 31.0, IE 10 and crome 36.0.1985.143. But the dose does not work if the CTRL keys are used.



 $('select').bind("click", function (event, target) {

        event.preventDefault();
        var CurrentIndex = event.target.selectedIndex==undefined? $(event.target).index(): event.target.selectedIndex
        var CurrentOption = $("option:eq(" + CurrentIndex+ ")", $(this));
        if ($(CurrentOption).attr('data-selected') == undefined || $(CurrentOption).attr('data-selected') == 'false') {
            $(CurrentOption).attr('data-selected', true);
        }
        else {
            $(CurrentOption).prop('selected', false).attr('data-selected', false);
        }

        $("option", $(this)).not(CurrentOption).each(function (Index, OtherOption) {
            $(OtherOption).prop('selected', ($(OtherOption).attr('data-selected') == 'true') ? true : false);
        });
         return false;
    });

      

+1


source







All Articles