Method one - if more than three, stops at three, still loads the new page:
Code:
function LineItemRpt(){
var i, cRecs = [], allowed = 3;
for (i = 0; i < document.forms[0].length; ++i){
if(cRecs.length === allowed){break;}
if (document.forms[0].elements[i].type == "checkbox"){
if (document.forms[0].elements[i].checked==true){
cRecs.push(document.forms[0].elements[i].name);
}
}
}
if (!cRecs.length){
alert("No records have been selected!");
} else {
window.open("LineItem_rpt.asp?recs=" + cRecs.join(','), "LineItemReport");
}
}
Method two - will not allow more than three, pops an alert to choose only three:
Code:
function LineItemRpt(){
var i, cRecs = [], allowed = 3, cb;
for (i = 0; i < document.forms[0].length; ++i){
if ((cb = document.forms[0].elements[i]).type == "checkbox" && cb.checked){
if(cRecs.length === allowed){alert('Please choose only 3 records'); return;}
cRecs.push(cb.name);
}
}
if (!cRecs.length){
alert("No records have been selected!");
} else {
window.open("LineItem_rpt.asp?recs=" + cRecs.join(','), "LineItemReport");
}
}
Bookmarks