开发者

How to copy the shipping address to billing address

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!


Give this a try.

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


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 :)


// 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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜