Category Archives: unobtrusive

JS: Unobtrusive Select All Checkboxes

I wrote last week about how I’m trying to improve my JavaScript skills. As a small exercise I have written this function for unobtrusively selecting/deselecting checkboxes in a form.
PLAIN TEXT
JAVASCRIPT:

function selectAll(box)

{

// get the elements name

var id = box.id;

var name = /^([a-z]+)(_select_all)$/i.exec(id);

 

name = name[1];

 

re = new RegExp('^'+name+'_[0-9]+$');

 

// get the elements stauts

var state = box.checked;

 

// get the [...]