Results 1 to 3 of 3

Thread: Over limit help

  1. #1
    Join Date
    Oct 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Over limit help

    I need to limit the records to 3 in this script.
    NE1 please help

    Code:
    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");
       }
    }
    Last edited by jscheuer1; 10-09-2013 at 01:06 PM. Reason: Format

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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");
       }
    }
    Last edited by jscheuer1; 10-09-2013 at 02:18 PM. Reason: code refinement
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!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>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Similar Threads

  1. Facebook Age Limit
    By Burgin in forum The lounge
    Replies: 21
    Last Post: 08-06-2011, 08:17 PM
  2. Limit file_get_contents?
    By JBottero in forum PHP
    Replies: 0
    Last Post: 04-26-2009, 07:21 PM
  3. Regarding news limit
    By vividona in forum PHP
    Replies: 0
    Last Post: 11-13-2008, 08:50 AM
  4. Every Size Got A Limit!!!
    By hantz in forum Looking for such a script or service
    Replies: 5
    Last Post: 09-28-2007, 11:49 AM
  5. aspUpload Limit
    By sasha hantz in forum ASP
    Replies: 0
    Last Post: 08-16-2007, 05:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •