html 循环遍历地址数组并根据选择填充输入字段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 循环遍历地址数组并根据选择填充输入字段相关的知识,希望对你有一定的参考价值。

<!-- Loop through address array and populate input fields based on selection -->
<script>
var shipnickname = [];
var shipfirst = [];
var shiplast = [];
var shipemail = [];
var shipphone = [];
var shipfax = [];
var shipcompany = [];
var shipaddress = [];
var shipaddress2 = [];
var shipcity = [];
var shipstate = [];
var shipzip = [];
var shipcountry = [];

<mvt:foreach iterator="address" array="addresses">
    shipnickname[&mvt:address:id;]='&mvt:address:nickname;';
    shipfirst[&mvt:address:id;]='&mvt:address:fname;';
    shiplast[&mvt:address:id;]='&mvt:address:lname;';
    shipemail[&mvt:address:id;]='&mvt:address:email;';
    shipphone[&mvt:address:id;]='&mvt:address:phone;';
    shipfax[&mvt:address:id;]='&mvt:address:fax;';
    shipcompany[&mvt:address:id;]='&mvt:address:comp;';
    shipaddress[&mvt:address:id;]='&mvt:address:addr;';
    shipaddress2[&mvt:address:id;]='&mvt:address:addr2;';
    shipcity[&mvt:address:id;]='&mvt:address:city;';
    shipstate[&mvt:address:id;]='&mvt:address:state;';
    shipzip[&mvt:address:id;]='&mvt:address:zip;';
    shipcountry[&mvt:address:id;]='&mvt:address:cntry;';
</mvt:foreach>

function SetShipTo(a) {
$("input[name=ShipFirstName]").val(shipfirst[a]);
$("input[name=ShipLastName]").val(shiplast[a]);
$("input[name=ShipEmail]").val(shipemail[a]);
$("input[name=ShipPhone]").val(shipphone[a]);
$("input[name=ShipFax]").val(shipfax[a]);
$("input[name=ShipCompany]").val(shipcompany[a]);

$("input[name=ShipAddress1]").val(shipaddress[a]);
$("input[name=ShipAddress2]").val(shipaddress2[a]);

$("input[name=ShipCity]").val(shipcity[a]);
$("input[name=ShipStateSelect]").val(shipstate[a]);

if ( $("input[name=ShipStateSelect]").val() != shipstate[a] ) { 
    $("input[name=ShipStateSelect]").val(''); $("input[name=ShipState]").val(shipstate[a]);
}
else {
    $("input[name=ShipState]").val('');
}

$("input[name=ShipZip]").val(shipzip[a]);
$("input[name=ShipCountry]").val(shipcountry[a]);
}

function ChangeShipTo() {
    if ( $("#ua_shipto option:selected").val() == '' ) {

    }
    else {
    var v = $("#ua_shipto option:selected").val();
    SetShipTo(v);
    }
}

var billnickname = [];
var billfirst = [];
var billlast = [];
var billemail = [];
var billphone = [];
var billfax = [];
var billcompany = [];
var billaddress = [];
var billaddress2 = [];
var billcity = [];
var billstate = [];
var billzip = [];
var billcountry = [];

<mvt:foreach iterator="address" array="addresses">
    billnickname[&mvt:address:id;]='&mvt:address:nickname;';
    billfirst[&mvt:address:id;]='&mvt:address:fname;';
    billlast[&mvt:address:id;]='&mvt:address:lname;';
    billemail[&mvt:address:id;]='&mvt:address:email;';
    billphone[&mvt:address:id;]='&mvt:address:phone;';
    billfax[&mvt:address:id;]='&mvt:address:fax;';
    billcompany[&mvt:address:id;]='&mvt:address:comp;';
    billaddress[&mvt:address:id;]='&mvt:address:addr;';
    billaddress2[&mvt:address:id;]='&mvt:address:addr2;';
    billcity[&mvt:address:id;]='&mvt:address:city;';
    billstate[&mvt:address:id;]='&mvt:address:state;';
    billzip[&mvt:address:id;]='&mvt:address:zip;';
    billcountry[&mvt:address:id;]='&mvt:address:cntry;';
</mvt:foreach>

function SetBillTo(b) {
$("input[name=BillFirstName]").val(billfirst[b]);
$("input[name=BillLastName]").val(billlast[b]);
$("input[name=BillEmail]").val(billemail[b]);
$("input[name=BillPhone]").val(billphone[b]);
$("input[name=BillFax]").val(billfax[b]);
$("input[name=BillCompany]").val(billcompany[b]);

$("input[name=BillAddress1]").val(billaddress[b]);
$("input[name=BillAddress2]").val(billaddress2[b]);

$("input[name=BillCity]").val(billcity[b]);
$("input[name=BillStateSelect]").val(billstate[b]);

if ( $("input[name=BillStateSelect]").val() != billstate[b] ) { 
    $("input[name=BillStateSelect]").val(''); $("input[name=BillState]").val(billstate[b]);
}
else {
    $("input[name=BillState]").val('');
}

$("input[name=BillZip]").val(billzip[b]);
$("input[name=BillCountry]").val(billcountry[b]);
}

function ChangeBillTo() {
    if ( $("#ua_billto option:selected").val() == '' ) {

    }
    else {
    var bv = $("#ua_billto option:selected").val();
    SetBillTo(bv);
    }
}
</script>

以上是关于html 循环遍历地址数组并根据选择填充输入字段的主要内容,如果未能解决你的问题,请参考以下文章

将输入字段推送到数组并循环遍历

根据另一个表单字段(单选按钮)预填充值 HTML 表单输入

循环遍历 JavaScript 对象数组并删除值

如何获取选择选项的值,并使用它来查询数组,以填充另一个输入

如何禁用使用手表循环遍历数组的可用时间?

从联系人中选择自动填充地址后,iOS UITextField 文本字段为空