Yes, I know I can use a <%%editingDateTime%%> default value but that only records the last edit details - not all edits to the particular field which may be updated many times. Inserting the date/time with the javascript button is handy and allows users to store the details immediately above every new entry to the text field (presuming the User does actually use the button as instructed) and it is working well for my purpose.
Date & Time works perfectly. Now I am now trying to add $memberInfo['username'] to the button's javascript function but I can't work out exactly how to achieve that so far? I need to keep a chronological record of updates.
I realise it will have to be an AJAX call as the $memberInfo['username'] will have to be delivered server-side. I've created a php script to successfully retrieve the $memberInfo['username']. Now I just have to successfully get the $memberInfo['username'] result to my javascript file? I've tried quite a few AJAX functions but they all either result in "undefined" or a broken javascript with no result. What AJAX function and where to include in my javascript file??? Any help or advice greatly appreciated.
This is what I have so far:
The text field button
Code: Select all
<button type="button" class="btn btn-success btn-xs" onclick="ajaxFunction();setStartTimeNow()"><span class="glyphicon glyphicon-pencil"></span><span style="color: #fff"> Insert Date/Time Stamp</span></button> - <i>Click button to insert new Date/Time Stamp</i><textarea class="form-control" name="possession" id="possession" rows="8"><%%VALUE(possession)%%></textarea>
Code: Select all
<?php
/* Get MemberInfo for date/time stamps */
$curr_dir = dirname(__FILE__);
include("{$curr_dir}/defaultLang.php");
include("{$curr_dir}/language.php");
include("{$curr_dir}/lib.php");
$mi = getMemberInfo();
echo $mi['username'];
?>
Code: Select all
function setStartTimeNow()
{
var theInput = document.getElementById("possession");
var now = new Date();
var date = [ "\n" + "Date: " + ((now .getDate() < 9 ? '0' : '') + (now .getDate())), ((now .getMonth() < 9 ? '0' : '') + (now .getMonth() + 1)), now.getFullYear() ];
var time = [ now.getHours(), now.getMinutes() ];
var suffix = ( time[0] < 12 ) ? "AM" : "PM" + "\n" ;
time[0] = ( time[0] < 12 ) ? time[0] : time[0] - 12;
time[0] = time[0] || 12;
for ( var i = 1; i < 3; i++ ) {
if ( time[i] < 10 ) {
time[i] = "0" + time[i];
}
}
// Return the formatted string
return theInput.value += date.join(".") + " " + time.join(":") + " " + suffix;
}