views:

117

answers:

2

Hi all 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!

+2  A: 

Give this a try.

var state = $('#state option:selected').val();
$('#bstate option[value=' + state + ']').attr('selected','selected');
patrick dw
grr, i was too slow :) + 1 for being fast and right
DannyLane
Gotta be snappy! ;o) Thanks for the +
patrick dw
Thanks for the help! +1
Jerry
A: 

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

Puaka
I already tried that before..not working..but thanks though.
Jerry