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');
});
}
});
});
我有一个调用,.ajax()
并且在该调用的内部设置了一个$("#existcustomers tr").click()
,并且在该单击内部处理事情的最合乎逻辑的方式将是.ajax()
对第一个内部的另一个调用,但是我正在寻找另一个选项。我现在想知道是否有一些简单的方法可以将事件挂钩#form-main
并在.data()
将数据设置为#form-main
. 一如既往地提前感谢大家提供与此代码相关的任何建议或评论!