Hello peeps
I'm developing an automated library book-lending system, which works fine, but I've got one little thing I want to add that I can't get to work.
When a someone turns up with the book they want to borrow, I have a loan slip form which has borrower details already entered (name, date borrowed, due date of return etc)... the only field that needs completing is the individual copy number of the book (every book in the library has a unique copy no). Most books in the library are loan copies, but some are reference only.
When the form is submitted a javascript function is called (... onSubmit="return validateForm()") which calls 2 functions that perform validation:
1) (checkBlankCopyNo) checks whether the copy no field is empty, and if so displays a javascript alert and stops the form being submitted
2) (ajaxCheckRef) if the field has a number entered, this checks if the copy number entered is of a reference or loan copy - if reference it should display an alert and stop the form submitting, else it would process the form
Now, this is where the problem lies... if I call function no 2 directly from the form (from a button for example) the AJAX function works as intended; but if it gets called from the Submit button, whereby the blank field check is performed, then the copy type check, no data seems to be sent back from the AJAX function.
It sounds really complicated when I've written it down, but in practice it isn't too bad! The code is below:
Code: Select all
/* VALIDATE FORM FUNCTIONS */
function validateForm() {
var checkValue;
checkValue = checkBlankCopyNo();
if (checkValue == false) { return checkValue; }
return ajaxCheckRef();
}
/* END */
/* FUNCTION TO CHECK IF COPY NO HAS BEEN LEFT BLANK */
function checkBlankCopyNo() {
if (document.forms["NewLoan"]["CopyNo"].value == "") {
alert("You must enter an item Copy Number!");
document.forms["NewLoan"]["CopyNo"].focus();
return false;
}
return true;
}
/* FUNCTION TO CHECK IF ENTERED COPY NO IS A REFERENCE COPY */
function ajaxCheckRef() {
var copyNo = document.forms["NewLoan"]["CopyNo"].value;
http.open("GET","ValidateCopy.php?CopyNo="+copyNo,true);
http.onreadystatechange = handleRefResponse;
http.send(null);
}
/* END */
function handleRefResponse() {
if (http.readyState==4) {
var loanType=http.responseText;
/* do stuff here */
}
}
/* END */
Anyone of you brainiacs got any ideas? ... cos I'm stumped!
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: