PDA

View Full Version : Over limit help



dlbhome
10-09-2013, 12:17 PM
I need to limit the records to 3 in this script.
NE1 please help


function LineItemRpt(){
var i;
var cRecs;
cRecs = "";
for (i = 0; i < document.forms[0].length; i++){
if (document.forms[0].elements[i].type == "checkbox"){
if (document.forms[0].elements[i].checked==true){
cRecs = cRecs + document.forms[0].elements[i].name;
if (i < document.forms[0].length){
cRecs = cRecs + ",";
}
}
}
}
if (cRecs == ""){
alert("No records have been selected!");
} else {
window.open("LineItem_rpt.asp?recs=" + cRecs, "LineItemReport");
}
}

jscheuer1
10-09-2013, 01:29 PM
Method one - if more than three, stops at three, still loads the new page:


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:


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");
}
}

vwphillips
10-09-2013, 01:29 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/

function LineItemRpt(){
var els=document.forms[0].elements,cRecs='',i=0;
for (; i < els.length; i++){
if (els[i].type == "checkbox"){
if (els[i].checked){
if (cRecs.split(',').length<4){
cRecs += els[i].name+',';
}
else {
els[i].checked=false;
}
}
}
}
if (cRecs == ""){
alert("No records have been selected!");
} else {
// window.open("LineItem_rpt.asp?recs=" + cRecs, "LineItemReport");
alert(cRecs);
}
}/*]]>*/
</script></head>

<body>
<form >
<input type="checkbox" name="rec" />
<input type="checkbox" name="rec" />
<input type="checkbox" name="rec" />
<input type="checkbox" name="rec" />
<input type="button" name="" value="Test" onmouseup="LineItemRpt();"/>
</form>

</body>

</html>