如何通过点击事件禁用智能街道/实时地址

How to disable SmartyStreets/LiveAddress via onclick event

本文关键字:街道 智能 实时 地址 何通过 事件      更新时间:2023-09-26

我继承了在SquirrelCart购物车应用程序中实现的SmartyStreets/LiveAddress代码,并且需要帮助找出语法以禁用SmartyStreets/LiveAddress验证,该事件将帐单地址字段复制到送货地址字段中。

特别是对于国际地址(即美国境外(,在他们已经验证了账单地址之后,必须通过送货地址的验证过程真的很烦人。

我目前已将地址初始化为:

/* SmartyStreets */
jQuery.LiveAddress(
    {
        key: "18924899",
        invalidMessage: "Not a valid US Postal address.</br>Please correct or certify below.",
        debug: "true",
        addresses: [
            // Squirrelcart billing address
            {
                id:         'Billing',
                street:     '#Bill_Street',
                city:       '#Bill_City',
                state:      '#Bill_State_or_Province',
                zipcode:    '#Bill_Postal_Code',
                country:    '#Bill_Country'
            },
            // Squirrelcart shipping address
            {
                id:         'Shipping',
                street:     '#Ship_Street',
                city:       '#Ship_City',
                state:      '#Ship_State_or_Province',
                zipcode:    '#Ship_Postal_Code',
                country:    '#Ship_Country'
            },
            // Squirrelcart account address
            {
                id:         'Account',
                street:     '#Street',
                city:       '#City',
                state:      '#State_or_Province',
                zipcode:    '#Postal_Code',
                country:    '#Country'
            }
        ],
        autoVerify: false,
        deactivate: 'Shipping'
    }
);

与将帐单邮寄地址复制到送货地址相关联的 HTML 代码为:

<p>If your shipping address is the same as your billing address, clicking the 
   "Same as Billing button will copy it into the fields below for you. 
   If your shipping address is different, please type it in the fields below.</p>
<div align="center"><a class="btn btn_same_as_billing" href="#">Same as Billing</a></div>

相关的 SquirrelCart JavaScript 函数:

/*************************************************************
    Setup various aspects of the store
*************************************************************/
function scStoreSetup() {
    < ... snip ... >
    $$('.btn_same_as_billing').addEvent('click',function(evt) {scAddressCopy(evt);});
    < ... snip ... >
}
/*************************************************************
    Function copies fields from billing to shipping address
*************************************************************/
function scAddressCopy(evt) {
    // prevents the page from jumping position
    evt.stop();
    var form    = document.address_form;
    var billFldId, shipFldId, billFld, shipFld;
    // loop thru fields
    for(x=0; x < form.elements.length; x++) {
        billFldId   = form.elements[x].id;
        billFld     = form.elements[x];
        // if we are on a bill field
        if (billFldId.indexOf('Bill_') != -1) {
            // change id to matching ship field
            shipFldId = billFldId.replace('Bill_','Ship_');
            // grab ship field and set it
            shipFld = document.getElementById(shipFldId);
            if (shipFld) shipFld.value = billFld.value;
        }
    }
}
/*************************************************************
    Handle things specific to address form
*************************************************************/
function addrForm(elem, evt) {
    if (elem.id == 'Bill_State_Other' && evt.type == 'keyup') {
        if (elem.value.length) {
            // set state or province field to 'Other'
            if (document.getElementById('Bill_State_or_Province')) document.getElementById('Bill_State_or_Province').value = 2
        }
    } else if (elem.id == 'Ship_State_Other' && evt.type == 'keyup') {
        if (elem.value.length) {
            // set state or province field to 'Other'
            if (document.getElementById('Ship_State_or_Province')) document.getElementById('Ship_State_or_Province').value = 2
        }
    } else if (elem.id == 'Bill_State_or_Province' && evt.type == 'change') {
        if (document.getElementById('Bill_State_Other')) {
            var stateOther = document.getElementById('Bill_State_Other');
            if (elem.options[elem.selectedIndex].value == '2') {
                stateOther.value = '';
                stateOther.focus();
            } else {
                stateOther.value='';
            }
        }
    } else if (elem.id == 'Ship_State_or_Province' && evt.type == 'change') {
        if (document.getElementById('Ship_State_Other')) {
            var stateOther = document.getElementById('Ship_State_Other');
            if (elem.options[elem.selectedIndex].value == '2') {
                stateOther.value = '';
                stateOther.focus();
            } else {
                stateOther.value='';
            }
        }
    }
}

似乎我应该能够通过使用onclick事件来禁用或停用LiveAddress(尤其是对于国际地址(,例如,

<a class="btn btn_same_as_billing" href="#" onclick="$('form#address_form').deactivate('Shipping');">Same as Billing</a>

其中"address_form"是表单的 ID:

<form id="address_form" class="sc_form" accept-charset="utf-8" name="address_form" action="<?php print $Form_Action?>" method="post">

我在拨入语法时遇到了真正的困难。帮我?

最好玛蒂

    <input type="button" name="Copy" value="Copy Billing Address" id="billingtoshipping_checkbox"> 
    <script type="text/javascript">
    $(document).ready(function(){
        $("#billingtoshipping_checkbox").click(function(){
            $("[id^='shipping_']").each(function(){
                data=$(this).attr("id")
                tmpID = data.split('shipping_');
                $(this).val($("#billing_"+tmpID[1]).val())
            })
        });
    });
</script>