我继承了在 SquirrelCart 购物车应用程序中实现的 SmartyStreets/LiveAddress 代码,并且需要帮助找出语法以通过将帐单地址字段复制到送货地址字段的 onclick 事件来禁用 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">
我在拨入语法时遇到了很大的困难。在这里帮帮我?
最好的,玛蒂