Skip to content

Instantly share code, notes, and snippets.

@markusfisch
Created March 22, 2012 22:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markusfisch/2165209 to your computer and use it in GitHub Desktop.
Save markusfisch/2165209 to your computer and use it in GitHub Desktop.
A bookmarklet to check a range of checkboxes

A bookmarklet to check a range of checkboxes

Ever wanted to be able to check a range of checkboxes? Like you do select a number of files in a file browser? May be to check some mails in your web based eMail client? Then this bookmarklet is for you.

Should work in all modern browsers.

I wrote this to help my lovely girlfriend manage her gmx.net inbox. Afterwards I found out, Google Mail does already sport this feature. Of course. So I guess this is only of interest for people using a gmx.net or web.de account.

How to get it?

Since GitHub doesn't allow forms or scripts in markdown files, you'll have to fetch it from here:

http://checkrange.markusfisch.de/

(function( w )
{
if( w.checkRange )
return;
w.checkRange =
{
last: null,
status: false,
init: function()
{
var i = document.getElementsByTagName( "input" );
for( var n = 0; n < i.length; ++n )
if( i[n].type === "checkbox" )
{
i[n].checkRangeNextOnClick = i[n].onclick;
i[n].onclick = function( ev )
{
if( ev.shiftKey &&
w.checkRange.last )
w.checkRange.check(
w.checkRange.last,
this );
w.checkRange.last = this;
w.checkRange.status = this.checked;
return this.checkRangeNextOnClick ?
this.checkRangeNextOnClick() :
true;
};
}
},
check: function( from, to )
{
var i = document.getElementsByTagName( "input" );
var found = false;
for( var n = 0; n < i.length; ++n )
{
if( i[n] === from ||
i[n] === to )
{
if( found )
break;
found = true;
}
if( !found )
continue;
i[n].checked = w.checkRange.status;
if( from === to )
break;
}
}
};
w.checkRange.init();
}( window ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment