Jump to content

Dynamicly Update


savagenoob

Recommended Posts

I am trying to dynamically update a portion of a webpage, using a javascript window.onload().  My problem is how to update the <div id = "name"> with the data returned from the php script.  I have 3 seperate <div>'s.

 

Html =

<input type="hidden" value="<?php echo $finid; ?>" id = "transid" name="transid" />
Agreement
<div id = "disclosure1"></div><br />
Certification
<div id = "disclosure2"></div><br />
Declarations
<div id = "disclosure3"></div>

 

The Javascript:

var getv=-1;
var page="getupdate.php";

function getData(){

while(getv!=-1){}
if (window.XMLHttpRequest) {
getv= new XMLHttpRequest();
if (getv.overrideMimeType){
getv.overrideMimeType("text/xml");
}
}else if (window.ActiveXObject) {
try {
getv = new ActiveXObject("Msxml2.xmlHttp");
getv.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}catch (e) {
try {
getv= new ActiveXObject("Microsoft.xmlHttp");
}catch (e) {}
}
}
ret=-1;
getv.onreadystatechange = function(){
if (getv.readyState == 4) {
ret=getv.responseText;
update(ret);
getv=-1;
}
};
var transid = document.getElementById('transid').value;
var queryString = "?transid=" + transid;
getv.open("GET", page + queryString);
try{
getv.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
catch(e){}
getv.send("");
return ret;

return 0;
settimeout("getData()",500);
}
function update(value){
var data=value.split(";");
document.getElementById("disclosure1").innerHTML=data[0];
document.getElementById("disclosure2").innerHTML=data[1];
document.getElementById("disclosure3").innerHTML=data[2];
}
window.onload = getData;

 

The PHP script:

<?php
require_once('includes/config.php');
require_once('includes/connect.php');

$transid = $_REQUEST['transid'];

$polquery  = mysql_query("SELECT * FROM disclosures WHERE transid = '$transid' AND disclosure = 'electronic' ORDER BY ID DESC LIMIT 1") or die(mysql_error());
$electronic = mysql_fetch_array($polquery);

$certquery  = mysql_query("SELECT * FROM disclosures WHERE transid = '$transid' AND disclosure = 'certification' ORDER BY ID DESC LIMIT 1") or die(mysql_error());
$certification = mysql_fetch_array($certquery);

$decquery  = mysql_query("SELECT * FROM disclosures WHERE transid = '$transid' AND disclosure = 'declarations' ORDER BY ID DESC LIMIT 1") or die(mysql_error());
$declarations = mysql_fetch_array($decquery);

if($electronic['complete'] == "accept"){
$data['disclosure1'] = 'Complete';
}
if($certification['complete'] == "accept"){
$data['disclosure2'] = 'Complete';
}
if($declarations['complete'] == "accept"){
$data['disclosure3'] = 'Complete';
}
echo $data['disclosure1'];
echo $data['disclosure2'];
echo $data['disclosure3'];
?>

 

The PHP scrilpt is where the problem is, how do i echo the word "Complete" to the associated <div> tag if the database shows accept.

Link to comment
https://forums.phpfreaks.com/topic/186918-dynamicly-update/
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.