X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   zip code check (https://forum.x-cart.com/showthread.php?t=21478)

cotc2001 05-01-2006 07:13 AM

zip code check
 
Hi,
Im looking at check_zipcode_js.tpl and havent got a clue how to do this.

What I need is to change the default 5 digit code check to a between 5 and 9 digit check (no more 9 digits)

this is the code below

Code:

{* $Id: check_zipcode_js.tpl,v 1.2.2.2 2004/09/15 12:01:47 max Exp $ *}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var us_zip_code = '{$lng.txt_error_us_zip_code|replace:"'":"\'"}';
var ca_zip_code = '{$lng.txt_error_ca_zip_code|replace:"'":"\'"}';
{literal}
function check_zip_code_field(cnt, zip){
var alert_str;
        if(!cnt || !zip)
                return true;
        alert_str = '';
        if (cnt.options[cnt.selectedIndex].value=="US") {
                if (zip.value.length!=5 && zip.value!="")
                        alert_str = us_zip_code;
        } else if (cnt.value=="CA") {
                if (zip.value.length!=6 && zip.value.length!=7 && zip.value!="")
                        alert_str = ca_zip_code;
        }

        if(alert_str.length > 0) {
                alert(alert_str);
                zip.focus();
                return false;
        } else
                return true
}
function check_zip_code(){
        return check_zip_code_field(document.forms["registerform"].b_country, document.forms["registerform"].b_zipcode) && check_zip_code_field(document.forms["registerform"].s_country, document.forms["registerform"].s_zipcode);
}
{/literal}
</SCRIPT>


I don't want to remove the check as is suggested in other posts, just extend it so that US and Canadian have to be between 5 - 9 digits.

Any ideas?

zaa 05-01-2006 08:40 AM

Try this one:

Code:

{* $Id: check_zipcode_js.tpl,v 1.2.2.2 2004/09/15 12:01:47 max Exp $ *}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var us_zip_code = '{$lng.txt_error_us_zip_code|replace:"'":"\'"}';
var ca_zip_code = '{$lng.txt_error_ca_zip_code|replace:"'":"\'"}';
{literal}
function check_zip_code_field(cnt, zip){
var alert_str;
  if(!cnt || !zip)
      return true;
  alert_str = '';
  if (cnt.options[cnt.selectedIndex].value=="US") {
      if (zip.value!="" && !(zip.value.length >=5 || zip.value.length <=9))
        alert_str = us_zip_code;
  } else if (cnt.value=="CA") {
      if (zip.value!="" && !(zip.value.length >=5 || zip.value.length <=9))
        alert_str = ca_zip_code;
  }

  if(alert_str.length > 0) {
      alert(alert_str);
      zip.focus();
      return false;
  } else
      return true
}
function check_zip_code(){
  return check_zip_code_field(document.forms["registerform"].b_country, document.forms["registerform"].b_zipcode) && check_zip_code_field(document.forms["registerform"].s_country, document.forms["registerform"].s_zipcode);
}
{/literal}
</SCRIPT>


maildodge 05-20-2006 01:52 AM

Thanks, I was looking for something like this. Worked a treat :D

cotc2001 05-20-2006 03:29 AM

Didn't work for me im afraid, it allowed users to use even just 1 digit for the zip code.

Vacman 05-21-2006 01:00 PM

I would like to take this to even a next step - I just encountered this problem today - not for the first time.

Sometimes my customer get a little over-zealous in filling out their order forms and by way of example, type in Marietta, CA with a zip code of 30062 - well it turns out that the state should have been Georgia, not California. My old e-Commerce software had a checker for this issue - would be nice for XCart to do this...


All times are GMT -8. The time now is 11:00 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.