...
Server Time:
= date("M d, Y, g:i:s a") ?>
Local Time:
= date("M d, Y, g:i:s a") ?>
...
//---------------------------------------------------------------
// Get local time
//---------------------------------------------------------------
function getLocalTimeTimer()
{
var curDate = new Date();
//curDate.toLocaleFormat('%b-%d-%Y'); // Dec-30-2011
var localTime = curDate.toLocaleTimeString();
//document.getElementById("timeclock-server-time").innerHTML = curDate + " " + localTime;
document.getElementById("timeclock-client-time").innerHTML = "Local time: " + localTime;
}
//---------------------------------------------------------------
// Get server time
//---------------------------------------------------------------
function getServerTimeTimer()
{
$.ajax({
// Controller method to call
//url: 'http://localhost:8080/catalog/site/build.php',
url: 'lib-get-ajax-data.php',
// Parameter data to pass in
data: {
cmd: 'get-server-time'
},
type: 'POST',
cache: false,
dataType : "json",
// Code to run if the request succeeds;
// the response is passed to the function
success: function(data) {
// process data
//console.log('data: respStatus: [' + data.respStatus + '], error: [' + data.error + '], timestamp: [' + data.timestamp + '], output: [' + data.output + ']');
var results = '';
if (data.respStatus == "ok") {
results = data.output;
} else {
results = '' +
'Error: ' + data.error + '
' +
(data.output.length > 0 ? '' + data.output + '
' : '') +
'';
}
$('#timeclock-server-time').html(results);
},
// Code to run if the request fails;
// the raw request and status codes are passed to the function
error: function( xhr, status, errorThrown ) {
//alert('Sorry, there was a problem! Error: ' + errorThrown + 'Status: ' + status + xhr);
//console.log('Error: ' + errorThrown );
//console.log('Status: ' + status );
console.dir( xhr );
},
// Code to run regardless of success or failure
complete: function( xhr, status ) {
//alert('The request is complete!');
}
});
}
No data';
}
?>
== Get Input Values ==
=== Combobox / Listbox (single select) ===
var selValue = $('#catalog-lang option:selected').val();
var selText = $('#catalog-lang option:selected').text();
Eg:
=== Listbox (muti-select) ===
var realvalues = [];
var textvalues = [];
$('#catalog-products :selected').each(function(i, selected) {
realvalues[i] = $(selected).val();
textvalues[i] = $(selected).text();
});
When using ''select-option'' controls, ''option:selected'' can be used:
$('#catalog-products option:selected').each(function(i, selected) {
...
}
Eg:
== DOM Manipulation ==
Get Javascript element:
$( "#foo" )[ 0 ]; // Equivalent to document.getElementById( "foo" )
Visibility on an input element and its label:
$('#myInput').hide();
$('label[for=\"myInput\"]').hide();