我想知道我是否可以将送货地址复制到帐单邮寄地址。当用户点击与送货地址相同时复选框。送货地址值将复制到开票输入字段。我完成了大部分部分,但我不确定如何将选择菜单(状态)值复制到帐单地址。我真的很感激任何帮助。
我的代码
$(document).ready(function(){
Jquery的
$('#same').click(function(){
if($('#same').attr('checked')){
$('#bfName').val($('#fName').val());
$('#blName').val($('#lName').val());
$('#baddress1').val($('#address1').val());
$('#baddress2').val($('#address2').val());
$('#bcity').val($('#city').val());
alert(($('#state option:selected').val())); //not sure what to do here
$('#bzip').val($('#zip').val());
};
});
HTML
<td><select name="state"> //shipping states......only partial codes.
<option value="">None
<option value="AL">Alabama
<option value="AK">Alaska
<option value="AZ">Arizona
<option value="AR">Arkansas
<option value="CA">California
<option value="CO">Colorado
<option value="CT">Connecticut
</select></td>
<td><select name="bstate"> //billing state................only partial codes.
<option value="">None
<option value="AL">Alabama
<option value="AK">Alaska
<option value="AZ">Arizona
<option value="AR">Arkansas
<option value="CA">California
<option value="CO">Colorado
<option value="CT">Connecticut
</select></td>
非常感谢!
答案 0 :(得分:11)
试一试。
var state = $('#state option:selected').val();
$('#bstate option[value=' + state + ']').attr('selected','selected');
答案 1 :(得分:1)
这有用吗?
$('#bstate').val($('#state').val());
您可能需要将id属性添加到该结算和发货状态选择为'astate'和'bstate',因为我似乎无法找到一个:)
答案 2 :(得分:1)
// make billing same as address
$('input[name=same]').click(function() {
//alert('Using the same address');
if ($("input[name=same]:checked").is(':checked')) {
$('#account_bill_fname').val($('#account_fname').val());
$('#account_bill_lname').val($('#account_lname').val());
$('#account_bill_address1').val($('#account_address1').val());
$('#account_bill_address2').val($('#account_address2').val());
$('#account_bill_city').val($('#account_city').val());
var state = $('select[name=account_state] option:selected').val();
$('select[name=account_bill_state] option[value=' + state + ']').attr('selected','selected');
var country = $('select[name=account_country] option:selected').val();
$('select[name=account_bill_country] option[value=' + country + ']').attr('selected','selected');
$('#account_bill_postal').val($('#account_postal').val());
};
});
在html页面上,州和国家是下拉列表,复选框是:
<input type="checkbox" name="same" value="Y" />