Whenever I click on the pop-up menu to select a customer, it pulls data using an ajax call and updates selections on a form. Everything is working fine, but if I click on .lookup-cust-hide
again, the JSON data (customer list) duplicates itself. Now I end up with two full lists of customers combined...
I'm considering the need to somehow clear the ajax call at the end???
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();
});