Feedback on: irt.org FAQ Knowledge Base Q1118
Comments:
Using names (name="chk_something") :
function checkAll(theChk) {
var f = theChk.form;
var chk = theChk.checked;
for (i=0;i<f.elements.length;i++) {
if (f.elements[i].name.indexOf('chk_') !=-1) {
f.elements[i].checked=chk;
}
}
}
using fixed part an a number (name="chk_1" to name="chk_10"):
numberOfChks = 10;
function checkAll(theChk) {
var f = theChk.form;
var chk = theChk.checked;
for (i=1;i<=numberOfChks;i++) {
f.elements["chk_"+i].checked=chk;
}
}
<input type="checkbox" name="allChecker" onClick="checkAll(this)">Select all
Worth:
Very worth reading
Comments:
Excellent work throughout your site! For the Q1118 item, I learned that one can check for a checkbox name that 'begins with' or 'contains' a recognizable item such as 'chk.' My checkbox names are dynamic from a Cold Fusion page. Subsequently, this took care of an immediate need this morning.
By the way, have you written and published any books that can be bought from Amazon?
Thanks!