I have a small script to update a page using AJAX. Basically, it is to update the information of the customer when the blur off a text field. The question is, I have about 10 fields that could possibly be updated. So, is it possible to write one function that would work for all of the fields? The code below is what I have so far...
The first function works fine. All of the data gets sent, and the .php page receives the variables fine. Within the callback, the alert also works fine. The code after the alert is what seems not to be working. All of the other AJAX functions are also working well, are written in about the same manner. The only exception is the variable in the "var ss = document.getElementById(div+ "Div");" part. All of the other functions have "var ss = document.getElementById("DivName");". So is there something that I am doing wrong? or this just can't be done?
Thanks in advance
SM
Code:
function updateCustomer(cid,field) {
var theValue = document.getElementById(field + "V").value;
if (searchReq.readyState == 4 || searchReq.readyState == 0) {
searchReq.open("GET", 'updateCustomer.php?id=' + cid + '&field=' + field + '&value=' + theValue, true);
alert("The value is: " + theValue);
searchReq.onreadystatechange = updateCustomerCB(field);
searchReq.send(null);
}
}
function updateCustomerCB(div) {
alert(div + "Div");
if (searchReq.readyState == 4) {
var ss = document.getElementById(div+ "Div");
ss.innerHTML = '';
var code = searchReq.responseText;
ss.innerHTML = code;
}
}
Thanks in advance
SM