Suchy Posted September 30, 2009 Share Posted September 30, 2009 I have a form where I can schedule events (set room, date, start and end time). When I click submit Ajax check if there is already something scheduled ta that time, date and room. function get_results() { if(httpObject.readyState == 4) { var conflict_results = httpObject.responseText; if (conflict_results != "0") { // Conflict - Room + Date + time already in use alert(conflict_results); conflict_status = 1; } else { // No Conflict conflict_status = 0; } } } function check_for_conflicts(form) { var workshop_room = form.room.value; var workshop_date = form.date.value; var workshop_time_start = form.time_start.value; var workshop_time_stop = form.time_stop.value; var conflict_status ; // check for schedule conflicts httpObject = getHTTPObject(); if (httpObject != null) { httpObject.open("GET", "check_conflicts.php?d=" + workshop_date + "&r=" + workshop_room + "&st=" + workshop_time_start + "&sp=" + workshop_time_stop, true); httpObject.send(null); httpObject.onreadystatechange = get_results; } if (conflict_status == 0) return true; else return false; } The problem is that get_results() function sets conflict_status variable, but it is not available in the check_for_conflicts() function. The way this supposed to work is that when there is a conflict, the conflict_status variable is set to 1 and based on that check_for_conflicts() function returns False and the form is not submited. How can I get the value of the conflict_status variable passed to the check_for_conflicts() function ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.