Jump to content

Problem passing variables


Suchy

Recommended Posts

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 ?

Link to comment
https://forums.phpfreaks.com/topic/176076-problem-passing-variables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.