user579984
user579984

Reputation: 160

JQuery unbind issue

I have some jquery that prevents a couple of select fields from being changed when a check box is ticked. This is working okay but I can't seem to get the unbind to work. I need the selects to work again when the checkbox is unticked.

$("input#same").live('click', function () {
    if ($("input#same").is(':checked')) {
        // Checked, copy values 
        $("input#shipping_first_name").val($("input#first_name").val()).attr("readonly", true);
        $("input#shipping_last_name").val($("input#last_name").val()).attr("readonly", true);
        $("input#shipping_address").val($("input#address").val()).attr("readonly", true);
        $("input#shipping_address2").val($("input#address2").val()).attr("readonly", true);
        $("input#shipping_city").val($("input#city").val()).attr("readonly", true);
        $("select#shipping_state").val($("select#state").val()).bind("change", function () {
            $("select#shipping_state").val($("select#state").val())
        });
        $("input#shipping_zip").val($("input#zip").val()).attr("readonly", true);
        $("select#shipping_country_code").val($("select#country_code").val()).bind("change", function () {
            $("select#shipping_country_code").val($("select#country_code").val())
        });
    } else {
        // Clear on uncheck 
        $("input#shipping_first_name").val("").removeAttr("readonly");
        $("input#shipping_last_name").val("").removeAttr("readonly");
        $("input#shipping_address").val("").removeAttr("readonly");
        $("input#shipping_address2")..val("").removeAttr("readonly");
        $("input#shipping_city").val("").removeAttr("readonly");
        $("select#shipping_state").val("").unbind("change");
        $("input#shipping_zip").val("").removeAttr("readonly");
        $("select#shipping_country_code").val("").unbind("change");
    }
});
$('#order').live('submit', function () {
    $('input[type=submit]', this).attr('disabled', 'disabled');
});
});

Upvotes: 0

Views: 602

Answers (1)

mr.b
mr.b

Reputation: 2708

Use .die() when you attached event using live. Please refer to here:http://api.jquery.com/die/

Upvotes: 1

Related Questions