<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Formatted Time</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
// Declare our request variable.
var request = false;
// Define a function that will make our request for us:
function retrieveDate() {
// Clear the curent request
request = false;
// Generate the request object and handle different browsers:
if (window.XMLHttpRequest) { // Mozilla & other compliant browsers
request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // Internet Explorer
request = new ActiveXObject("Microsoft.XMLHTTP");
}
// If we don't have a request object, then error out.
if (!request) {
alert('Browser does not support AJAX!');
return false;
}
// Ok, now we are ready. Make the request, and tell it to run the
// function 'updateDate' when it gets data back.
request.onreadystatechange = updateDate;
// Open the connection, sending the current value of the form element:
request.open('GET',
'time.php?format=' + escape(document.myform.dformat.value), true);
request.send(null);
}
// The function that will accept the data, and update the page:
function updateDate() {
// Make sure that the state is '4', which means finished:
if (request.readyState == 4) {
// Make sure that the status is 200, or 'ok'
if (request.status == 200) {
// If so, read the result back in as XML:
var xml = request.responseXML;
// Now, parse the 'result' out of the XML:
var result = xml.getElementsByTagName('result').item(0);
// And now, update the text on the page:
var text = document.getElementById('datetext');
text.innerHTML = result.firstChild.data;
} else {
alert('Error performing request!' + request.status);
}
}
}
</script>
</head>
<body>
<p>Click the update button below to receive the current date. Insert any valid PHP date() format string in the field to format it accordingly.</p>
<p id="datetext">--DATE GOES HERE--</p>
<form id="myform" name="myform"><p>
<input type="text" id="dformat" name="dformat" value="r" />
<input type="button" value="Update" onclick="retrieveDate()" />
</p></form>
</body>
</html>