I'm trying to add the option of selecting multiple checkboxes at the same time in an apex tabular form:
I originally wanted to write some Javascript allowing to select a range of checkboxes using the intutive "standard" way of spreadsheet software to:
- select first item
- press & hold shift
- select last item
But for the sake of easier implementation, I decided to just use an apex button (setting a REQUEST). My code should select all checkboxes from the first selected to the last selected. But it simply doesn't and I can't see why.
var $firstChecked = $('input[type=checkbox]:checked').first();
var $lastChecked = $('input[type=checkbox]:checked').last();
$firstChecked.nextUntil($lastChecked, 'input[type=checkbox]').each(function () {
$(this).prop('checked', true);
});
I'm almost sure that I am doing something wrong with nextUntil because
$('input[type=checkbox]:checked').prop('checked', false);
works just fine.
[JSFiddle] (using the copied html code from apex)
- What is wrong with my javascript code?
- Is it possible to code the "intuitive way" with jQuery (logging the shift key)?