johnmac249
johnmac249

Reputation: 3

Javascript with Safari doesn't work - all other browser do

I have this script which duplicates the form fields when a "Same as Billing" checkbox is clicked from one form to another. It works fine except in Safari it won't transfer the state selection from the original form. The form field for the state is a select box. Any help is appreciated.

$(document).ready(function () {
    $("#same").click(function(){
        if($("#same:checked").length >= 0) {
            $('#first_name_ship').val($('#first_name_bill').val());
            $('#last_name_ship').val($('#last_name_bill').val());
            $('#address1_ship').val($('#address1_bill').val());
            $('#address2_ship').val($('#address2_bill').val());
            $('#city_ship').val($('#city_bill').val());
            var selected_state = $('#state_bill_select   option:selected').val();
            $('#state_ship_select option[value=' + selected_state + ']').attr('selected','selected');
            $('#zip_ship').val($('#zip_bill').val());

Upvotes: 0

Views: 295

Answers (1)

es_
es_

Reputation: 66

You can use

.prop('selected', true)

instead of

.attr('selected','selected');

which might work better with safari in general.

Try that out.

Upvotes: 1

Related Questions