I have a pop-up menu that I select customers from. It is populated with an ajax call and selections are updated on a form. This works fine, however when I click on the .lookup-cust-hide
a second time the json data (my customer list) repeats itself. I now have two full list of customers concatenated..
I'm thinking I need to clear the ajax call at the end somehow???
javascript:
$("#customer .lookup-cust-hide").click(function() {
$("#contactdiv1").css("display", "block");
$.ajax({
url: 'customer_fill.php',
data: {action:"invoice"},
dataType: 'json',
success: function(data){
populateSelectBoxes($('#contactdiv1 #dropdown'), data);
function populateSelectBoxes($select, data) {
var customers = [];
$.each(data, function() {
customers.push('<li data-value="'+this.autonum+'">' + this.customer + '</li>');
});
$select.append(customers.join(''));
}
function populateTableRow($tableBody, data, selectedCustomerAutonum) {
var customers;
$.each(data, function() {
if (this.autonum == selectedCustomerAutonum) {
customers = this;
return false;
}
});
$($tableBody).val(customers.customer+ '\n' + customers.address1 + '\n' + customers.address2 + '\n' + customers.address3);
}
$('#contactdiv1 #dropdown li').click(function(e) {
var selection = $(this).attr("data-value");
$(this).parent().parent().parent().hide();
populateTableRow($('#customer-title'), data, selection);
});
}
});
});
$("#contact #cancel").click(function() {
$(this).parent().parent().hide();
});