spenoir
04-16-2008, 12:59 PM
Can anyone help me with this JQuery code. I've excluded the document.ready function and the html but basically the code is just meant to copy billing address over to the delivery address when a checkbox is clicked.
I've solved it by hard coding each individual id and replacing their values, but it would be nice to write a class that you could reuse.
This code would used as part of a class.
dispVals = function() {
var str = $('#billing_addr :input').serialize();
var result = str.split('&');
for (x=0; x<result.length;x++) {
var deliveryValues = (result[x].substring((result[x].indexOf('=') + 1)));
//alert(deliveryValues[1]);
$('#result').html('<p>'+deliveryValues+'</p>');
delFields = $('#delivery_addr :input') ;
jQuery.each(delFields, function() {
$(this).val(deliveryValues[x]);
});
}
$("#delivery_same_as_billing").click( function() {
dispVals();
})
At the moment it puts all the values into every field but replaces them so that you end up with the last value in the array in each delivery address field.
:thumbsup:
I've solved it by hard coding each individual id and replacing their values, but it would be nice to write a class that you could reuse.
This code would used as part of a class.
dispVals = function() {
var str = $('#billing_addr :input').serialize();
var result = str.split('&');
for (x=0; x<result.length;x++) {
var deliveryValues = (result[x].substring((result[x].indexOf('=') + 1)));
//alert(deliveryValues[1]);
$('#result').html('<p>'+deliveryValues+'</p>');
delFields = $('#delivery_addr :input') ;
jQuery.each(delFields, function() {
$(this).val(deliveryValues[x]);
});
}
$("#delivery_same_as_billing").click( function() {
dispVals();
})
At the moment it puts all the values into every field but replaces them so that you end up with the last value in the array in each delivery address field.
:thumbsup: