Question : Ajax not returning value to DIV

Hello, the attached script I am using below works perfect except for the part that returns the value to the div.

If the form I am using run ajaxFunction() that function it returns a value to the div= "message"

If I use the function ajaxSeller() it runs the php script successfully but does not return a value to the div="message" ...I am just trying to figure out how to get the value to populate the div..thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
<script type="text/javascript">
 
var time_variable;
 
function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
   }
   catch (e) {
     try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
     }
     catch (e2) {
       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
     }
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}
 
var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object
 
function ajaxFunction() {
  var getdate = new Date();  //Used to prevent caching during ajax call
  if(xmlhttp) { 
  	var b_firstname = document.getElementById("b_firstname");
	var b_lastname = document.getElementById("b_lastname");
	var b_address = document.getElementById("b_address");
	var b_city = document.getElementById("b_city");
	var b_state = document.getElementById("b_state");
	var b_zip = document.getElementById("b_zip");
	var b_phone = document.getElementById("b_phone");
	var b_fax = document.getElementById("b_fax");
	var b_cell = document.getElementById("b_cell");
	var b_email = document.getElementById("b_email");
	var b_comments = document.getElementById("b_comments");
    xmlhttp.open("POST","testing.php",true); //calling testing.php using POST method
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlhttp.send("b_firstname=" + b_firstname.value + "&b_lastname=" + b_lastname.value + "&b_address=" + b_address.value + "&b_city=" + b_city.value + "&b_state=" + b_state.value + "&b_zip=" + b_zip.value + "&b_phone=" + b_phone.value + "&b_fax=" + b_fax.value + "&b_cell=" + b_cell.value + "&b_email=" + b_email.value + "&b_comments=" + b_comments.value);

  }
  
}
 function ajaxSeller() {
  var getdate = new Date();  //Used to prevent caching during ajax call
  if(xmlhttp) { 
  	var s_firstname = document.getElementById("s_firstname");
	var s_lastname = document.getElementById("s_lastname");
	var s_address = document.getElementById("s_address");
	var s_city = document.getElementById("s_city");
	var s_state = document.getElementById("s_state");
	var s_zip = document.getElementById("s_zip");
	var s_phone = document.getElementById("s_phone");
	var s_fax = document.getElementById("s_fax");
	var s_cell = document.getElementById("s_cell");
	var s_email = document.getElementById("s_email");
	var s_comments = document.getElementById("s_comments");
    xmlhttp.open("POST","sellerins.php",true); //calling testing.php using POST method
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xmlhttp.send("s_firstname=" + s_firstname.value + "&s_lastname=" + s_lastname.value + "&s_address=" + s_address.value + "&s_city=" + s_city.value + "&s_state=" + s_state.value + "&s_zip=" + s_zip.value + "&s_phone=" + s_phone.value + "&s_fax=" + s_fax.value + "&s_cell=" + s_cell.value + "&s_email=" + s_email.value + "&s_comments=" + s_comments.value);

  }
  
}
function handleServerResponse() {
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
       document.getElementById("message").innerHTML=xmlhttp.responseText; //Update the HTML Form element
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}
</script>

Answer : Ajax not returning value to DIV

Okay, thought you could change the logic you used.

anyhow, here is the solution.

1- change div id for buyer to message_buyer
2- change div id for seller to message_seller
3- change eventhandler to accept a div id
4- pass the div id with each function

the updated html is attached

javascript function modifications:

xmlhttp.onreadystatechange  = function (){ handleServerResponse("message_buyer") };

:
:
function handleServerResponse( div_id ) {
:
:
document.getElementById(div_id).innerHTML=xmlhttp.responseText; //Update the HTML Form element


should be working now.

 
html file updated code
 
Random Solutions  
 
programming4us programming4us