Adding a Timestamp to the HTML Editor

Adding a Timestamp to the HTML Editor

by David Mark Weiss -
Number of replies: 0
I have created the JS for adding a button to the HTML editor that woudl insert a timestamp into the field. I can do it on the MAMP instance on my laptop, but not on our test server or production server.

For instance, in the JOurnal module in edit.php you read this toward the end.

include("edit.html");

if ($usehtmleditor) {
use_html_editor("text");
}

This seems to add the following script to the page when served from the test server or the production server:

<script type="text/javascript" defer="defer">
//<![CDATA[

editor_1cb251ec0d568de6a929b520c4aed8d1 = new HTMLArea('edit-text');
var config = editor_1cb251ec0d568de6a929b520c4aed8d1.config;
config.pageStyle = "body { background-color: #ffffff; font-family: Trebuchet MS,Verdana,Arial,Helvetica,sans-serif; }";
config.killWordOnPaste = true;
config.fontname = {
"Trebuchet": 'Trebuchet MS,Verdana,Arial,Helvetica,sans-serif',
"Arial": 'arial,helvetica,sans-serif',
"Courier New": 'courier new,courier,monospace',
"Georgia": 'georgia,times new roman,times,serif',
"Tahoma": 'tahoma,arial,helvetica,sans-serif',
"Times New Roman": 'times new roman,times,serif',
"Verdana": 'verdana,arial,helvetica,sans-serif',
"Impact": 'impact',
"Wingdings": 'wingdings'};
editor_1cb251ec0d568de6a929b520c4aed8d1.generate();
//]]>
</script>

Something in this script seems to prevent adding the time stamp.

My JS code looks like this:

<script type="text/javascript">
function TEST()
{

var d = new Date();
var currYear = d.getFullYear();
var currMonth = d.getMonth() + 1;
var currDate = d.getDate();
var currHour = d.getHours();
var currMin = d.getMinutes();
time = "\r\r" + (currMonth < 10 ? "0" : "") + currMonth + "-" + (currDate < 10 ? "0" : "") + currDate + "-" + currYear + " " +
(currHour < 10 ? "0" : "") + currHour + ":" +
(currMin < 10 ? "0" : "") + currMin + "\r";
theInput = document.getElementById("edit-text");

theInput.value += time;
}

Where the id of the textarea resolves to "edit-text".

When I change the name of the text area, it inserts just fine but then the text in the field doesn't save. So there is something funny going on at a basic level, it seems to me.

I tried getElementByName and that didn't work either.

So I am stumped.

If someone can tell me what I am doing wrong I would appreciate it, OR I need a good moodle programmer to pay to fix this. Thanks for listening.

Sincerely,

Mark Weiss
USU
Average of ratings: -