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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.