Jump to content

Ajax Checkbox onChange problem


JeremyA

Recommended Posts

I am having a problem with the following code.  I have successfully loaded some of my php files based on the users selection.  However on the checkbox options I am having trouble.  When a user clicks on newphone or newcomputer it loads their respective .php files.  However if either one of the checkboxes are selected I want it to load a building.php file.  The code below works because of the alert which triggers the xmlhttp.status of = 200.  If the alert is not in there the call fails because the xmlhttp.status is not set.  Maybe I am looking at this problem all wrong.

 

  //Create a boolean variable to check for a valid Internet Explorer instance.
  var xmlhttp = false;
  var NewComputer = false;
  var NewPhone = false;

  //Check if we are using IE.
  try {
    //If the Javascript version is greater than 5.
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    //alert ("IE for reals?  Upgrade please!");
  } catch (e) {
    //If not, then use the older active x object.
    try {
      //If we are using Internet Explorer.
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      //alert ("IE for reals?  Upgrade please!");
    } catch (E) {
      //Else we must be using a non-IE browser.
      xmlhttp = false;
    }
  }

  //If we are using a non-IE browser, create a javascript instance of the object.
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    xmlhttp = new XMLHttpRequest();
    //alert ("You are not using Microsoft Internet Explorer");
  }

  function MakeRequest(ServerPage, objID) {

    var obj = document.getElementById(objID);
    xmlhttp.open("GET", ServerPage);
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        obj.innerHTML = xmlhttp.responseText;
      }
    }
    xmlhttp.send(null)
  }
	function EvaluateNeedsPhone(MyForm){

	if (MyForm.NeedsPhone.checked){
			MakeRequest('New Phone.php','3');
			NewPhone = true;

		}
		else{
			MakeRequest('BlankPage.html','3');
			NewPhone = false; 		
		}
		LoadBuilding();
	}


	function EvaluateNeedsComputer(MyForm){


	if (MyForm.NeedsComputer.checked){
			NewComputer = true;
			MakeRequest('New Computer.php','2');
		}

		else{
			//This will remove area's that are deselected
			NewComputer = false;
			MakeRequest('BlankPage.html','2');
		}
		LoadBuilding();
	}

	function LoadBuilding(){


		if (NewPhone == true || NewComputer == true){
    		alert("Please fill out the building");
    		MakeRequest('Building.php','4');
		}
		else{
			alert("You no longer need to fill out your building");
			MakeRequest('BlankPage.html','4');
		}
	}

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.