Limiting the Length of ShopSite Checkout Fields

Forum Forums Tutorials Limiting the Length of ShopSite Checkout Fields

This topic contains 0 replies, has 1 voice, and was last updated by  Anonymous 9 years, 1 month ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #48797

    Anonymous
    Participant

    You can use the following javascript on your checkout page to limit the length of text fields. It can be entered in:

    Commerce Setup > Order System > Checkout Screen – Text at the bottom of the Checkout screen:

     

    <script type="text/javascript"> 
     
     window.onload = function(){ 
       var LimitCheckout = { 
         useBilling: document.billing.usebilling.checked, 
         commentsBox: document.billing.Comments, 
         commentsLimit: 0, 
         billing_fields:[{ 
             Email: 0, 
             Title: 0, 
             First: 0,    
             Middle: 0, 
             Last: 0, 
             Suffix: 0, 
             Company: 0, 
             Address: 0, 
             Address2: 0, 
             City: 0,    
             Zip: 0, 
             Phone: 0 
        }], 
         shipping_fields:[{ 
             ShipTitle: 0,    
             ShipFirst: 0,      
             ShipMiddle: 0, 
             ShipLast: 0, 
             ShipSuffix: 0, 
             ShipCompany: 0,    
             ShipAddress: 0,    
             ShipAddress2: 0,    
             ShipCity: 0, 
             ShipZip: 0,            
             ShipPhone: 0 
         }], 
         limitCommentBox: function(l_val){ 
             document.billing.Comments.onkeyup = function(){ 
               if (document.billing.Comments.value.length > l_val) { 
                 document.billing.Comments.value = document.billing.Comments.value.substring(0, l_val); 
               } 
             } 
     
             document.billing.Comments.onkeydown = function(){ 
                if (document.billing.Comments.value.length > l_val) { 
                   document.billing.Comments.value = document.billing.Comments.value.substring(0, l_val); 
                } 
             } 
         }, 
         setFieldLimit: function(l_field, f_limit){ 
             var limit_field = document.getElementsByName(l_field); 
             for(m=0; m<limit_field.length; m++){ 
                 limit_field[m].maxLength = f_limit; 
             } 
         }, 
         limitFields: function(){ 
             
             for(var b_index in LimitCheckout.billing_fields[0]) { 
               if(LimitCheckout.billing_fields[0][b_index] > 0){ 
                    LimitCheckout.setFieldLimit(b_index, LimitCheckout.billing_fields[0][b_index]); 
                } 
             } 
             for(var s_index in LimitCheckout.shipping_fields[0]) { 
               if(LimitCheckout.shipping_fields[0][s_index] > 0){ 
                   
                    LimitCheckout.setFieldLimit(s_index, LimitCheckout.shipping_fields[0][s_index]); 
                } 
             } 
     
             if(LimitCheckout.commentsBox != undefined){ 
                 if(LimitCheckout.commentsLimit > 0){ 
                     LimitCheckout.limitCommentBox(LimitCheckout.commentsLimit); 
                 } 
             } 
         } 
             
     } 
     
         LimitCheckout.limitFields(); 
     } 
     </script> 
    

     

    You will notice the script contains a list of billing fields (billing_fields) and shipping fields (shipping_fields) with a zero after each. Any field with a value of zero is not limited in length by this script. You can set any fields you would like to be restricted to the maximum number of characters you would like to allow for the field and the field will be restricted. You can also restrict the length of the text in the Customer Comments box (if you are using one on your checkout page) using the:

    commentsLimit: 0

    variable in the script.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.