View Single Post
Old 10-24-2008, 03:35 PM   #8 (permalink)
chrisb
The Wanderer
 
Join Date: Oct 2008
Location: Florida
Posts: 5
Thanks: 1
chrisb is on a distinguished road
Default

I have put together a very simple example using the method I described. Please see Timer Test Page .. After 5 seconds it updates and says it was updated. If you view source you will see all of the javascript (AJAX) require to do it. You should be able to pick it apart to make it do what you want.

Please note that I am just using basic knowledge gathered from resources. There is proably a better way to handle it, but eh I said I could do it and here is how :P

timer.php Page Code:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function startTimer()
{
var t=setTimeout(updateInfo,5000);
}

function updateInfo() {
		var data = document.getElementById('timer_registration').value;
		sndReq( data );		
	}//~

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}//~

var http = createRequestObject();

function sndReq(action) {
	//note( 'sndReq: ' + action );
    http.open('get', 'updater.php?action='+action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}//~

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
	var obj = document.getElementById('updatediv');
	obj.innerHTML = response;

    }
   
}//~



</script>
</head>

<body onLoad="startTimer();">
<div id="updatediv"></div>
<form action="#" method="get">
<input name="timer_registration" type="text" id="timer_registration" value="Example Title Registration" size="45"  />
</form>
</body>
</html>
updater.php Code:
PHP Code:
if ($_GET['action']) {
$data $_GET['action'];

// Make database update query....

// If update went ok
echo "Updated Data with $data";

chrisb is offline  
Reply With Quote
The Following User Says Thank You to chrisb For This Useful Post:
iory (10-24-2008)