如何将送货地址复制到帐单地址

发布于 2024-08-30 00:20:26 字数 1560 浏览 7 评论 0原文

我想知道是否可以将送货地址复制到帐单地址。当用户单击与送货地址相同的复选框时。送货地址值将被复制到账单输入字段。我完成了大部分部分,但我不确定如何将选择菜单(状态)值复制到帐单地址。我真的很感谢任何帮助。

我的代码

$(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>

非常感谢!

I like to know if I can copy the shipping address to billing address. When a user clicks same as shipping address checkbox. The shipping address value will be copied to billing input field. I got most of the parts done but I am not sure how to copy select menu (states) value to billing address. I really appreciate any helps.

My code

$(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>

Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

じ违心 2024-09-06 00:20:26

尝试一下。

var state = $('#state option:selected').val();
$('#bstate option[value=' + state + ']').attr('selected','selected');

Give this a try.

var state = $('#state option:selected').val();
$('#bstate option[value=' + state + ']').attr('selected','selected');
毁梦 2024-09-06 00:20:26

这有用吗?

  $('#bstate').val($('#state').val());

您可能需要将 id 属性添加到账单和运输状态中,选择“astate”和“bstate”,因为我似乎找不到:)

does this work ?

  $('#bstate').val($('#state').val());

you may need to add id attribute to that billing and shipping state select as 'astate' and 'bstate', as i can't seems to find one :)

吃→可爱长大的 2024-09-06 00:20:26
// 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" />
// 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());
      };              
    });

on the html page the state and country are dropdowns and the checkbox is:

<input type="checkbox" name="same" value="Y" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文