i have more than 1 live change that monitors the input and replicates into another field – works great on the first name but any other field after that does not work for some reason…. anyone got any ideas?
$("input#same_shipping_address_first_name").live('change', function() {
$('input#same_billing_address_first_name').val($('input#same_shipping_address_first_name').val());
});
$("input#same_billing_address_last_name").live('change', function() {
$('input#same_billing_address_last_name').val($('input#same_shipping_address_last_name').val());
});
$("input#same_billing_address_address_line_1").live('change', function() {
$('input#same_billing_address_address_line_1').val($('input#same_shipping_address_address_line_1').val());
});
$("input#same_billing_address_address_line_2").live('change', function() {
$('input#same_billing_address_address_line_2').val($('input#same_shipping_address_address_line_2').val());
});
$("input#same_billing_address_address_line_3").live('change', function() {
$('input#same_billing_address_address_line_3').val($('input#same_shipping_address_address_line_3').val());
});
$("input#same_billing_address_town_city").live('change', function() {
$('input#same_billing_address_town_city').val($('input#same_shipping_address_town_city').val());
});
$("input#same_billing_address_county").live('change', function() {
$('input#same_billing_address_county').val($('input#same_shipping_address_county').val());
});
$("input#same_billing_address_postcode").live('change', function() {
$('input#same_billing_address_postcode').val($('input#same_shipping_address_postcode').val());
});
It appears that you’d want to add the live listener to same_shipping_address_last_name, rather than same_billing_address_last_name, as it currently is.
Right now, you’re just overwriting the value of a input whenever that input changes. In your first_name example, you’re overwriting the value of another input when the input changes, which makes more sense.
You could probably address all of these inputs with just one listener, though. If you add the
shippingclass to the first set of inputs, for instance:You could of course do something like this without the class as well:
As others have pointed out, use
.onor.delegate(depending on jQuery version) over.live.