flagUpdateCustomer = 0;
$("input#checknames").click(function () {
$.ajax({
url: 'php.scripts/checknames.php',
data: { firstname: $("input#firstname").val(),
lastname: $("input#lastname").val(),
address1: $("input#address1").val(),
address2: $("input#address2").val(),
city: $("input#city").val(),
state: $("input#state").val(),
zip: $("input#zip").val(),
phone: $("input#phone").val(),
email: $("input#email").val(),
cell: $("input#cell").val()
},
type: 'post',
async: false,
success: function (output) {
var obj = $.parseJSON(output);
$("#existcustomers").empty();
for (var iCnt = 0; iCnt < obj.length; iCnt++) {
if (obj[iCnt].firstname == null) { obj[iCnt].firstname = ""; }
if (obj[iCnt].lastname == null) { obj[iCnt].lastname = ""; }
if (obj[iCnt].address1 == null) { obj[iCnt].address1 = ""; }
if (obj[iCnt].address2 == null) { obj[iCnt].address2 = ""; }
if (obj[iCnt].city == null) { obj[iCnt].city = ""; }
if (obj[iCnt].state == null) { obj[iCnt].state = ""; }
if (obj[iCnt].zip == null) { obj[iCnt].zip = ""; }
if (obj[iCnt].phone == null) { obj[iCnt].phone = ""; }
if (obj[iCnt].email == null) { obj[iCnt].email = ""; }
if (obj[iCnt].cell == null) { obj[iCnt].cell = ""; }
var newRow = $("<tr><td>" + obj[iCnt].firstname + "</td><td>" + obj[iCnt].lastname + "</td><td>" + obj[iCnt].address1 + "</td><td>" + obj[iCnt].address2 + "</td><td>" + obj[iCnt].city + "</td><td>" + obj[iCnt].state + "</td><td>" + obj[iCnt].zip + "</td><td>" + obj[iCnt].phone + "</td><td>" + obj[iCnt].email + "</td><td>" + obj[iCnt].cell + "</td></tr>").data('id',obj[iCnt].id);
$("#existcustomers").append(newRow);
}
$("#existcustomers tr").hover(function () { $(this).addClass("highlight"); }, function () { $(this).removeClass("highlight"); });
$("#existcustomers tr").click(function () {
$("#form-main").data('id', $(this).data('id'));
$("input#firstname").val($(this).children(":eq(0)").text());
$("input#lastname").val($(this).children(":eq(1)").text());
$("input#address1").val($(this).children(":eq(2)").text());
$("input#address2").val($(this).children(":eq(3)").text());
$("input#city").val($(this).children(":eq(4)").text());
$("input#state").val($(this).children(":eq(5)").text());
$("input#zip").val($(this).children(":eq(6)").text());
$("input#phone").val($(this).children(":eq(7)").text());
$("input#email").val($(this).children(":eq(8)").text());
$("input#cell").val($(this).children(":eq(9)").text());
$("input#firstname").attr('disabled', 'disabled');
$("input#lastname").attr('disabled', 'disabled');
$("input#address1").attr('disabled', 'disabled');
$("input#address2").attr('disabled', 'disabled');
$("input#city").attr('disabled', 'disabled');
$("input#state").attr('disabled', 'disabled');
$("input#zip").attr('disabled', 'disabled');
$("input#phone").attr('disabled', 'disabled');
$("input#email").attr('disabled', 'disabled');
$("input#cell").attr('disabled', 'disabled');
$("#form-main").data('firstname', $("input#firstname").val());
$("#form-main").data('lastname', $("input#lastname").val());
$("#form-main").data('address1', $("input#address1").val());
$("#form-main").data('address2', $("input#address2").val());
$("#form-main").data('city', $("input#city").val());
$("#form-main").data('state', $("input#state").val());
$("#form-main").data('zip', $("input#zip").val());
$("#form-main").data('phone', $("input#phone").val());
$("#form-main").data('email', $("input#email").val());
$("#form-main").data('cell', $("input#cell").val());
//I am trying to determine how to call .ajax again to set my $_SESSION in PHP
//A recursive call to .ajax does not seem to be a good option here
//I was hoping to see somthing about an onchange or onupdate event in the jQuery docs
//for .data() however I had no such luck. Perhaps could I use just the onchange()
//event of #form-main? Essentially once the data is set in #form-main I have to call
//.ajax again for add.customer.session.php. I am confused right now.
//????????????????
//
//
$('#form-main').css('background-color', 'green');
});
}
});
});
I have a call to .ajax() and inside of that call there is set a $("#existcustomers tr").click() and inside of that click the most logical way for to handle things would be another call to .ajax() inside of the first however I am looking for another option. I am wondering at this point if there is some easy way to hook an event to #form-main and run some code after .data() sets the data to #form-main. As always thank you all in advance for any suggestions or commentary related to this code!
I don’t think you have a recursive problem here. You just have chained ajax calls. This would really only be a problem if it could loop around around and call the original action again.
Since know that your first ajax call will make another ajax call, you could make both at the same time as an asynchronous call or if you have control over the server API, allow for both types of data to set/requested in one call.