When and Who auto inserted textarea
A textarea to automatically insert who and when adding a further comment.
by Swarts
HTML
<html>
<head></head>
<body>
<textarea id="t" cols=50 rows=10></textarea><br /><button>Submit</button>
</body>
</html>
JavaScript
var updated = false;
var uname = 'Joe Black';
Date.prototype.formatMMDDYYYY = function(){
return ('0' + this.getDate()).slice(-2) + '/'
+ ('0' + (this.getMonth()+1)).slice(-2) + '/'
+ this.getFullYear();
};
jQuery(function() {
$('button').click(function() {
updated = false;
});
$('#t').keydown(function(evt) {
if(updated) return;
if(evt.which === 13) evt.preventDefault();;
var newline = ($(this).val() === '') ? '' : '\n\n';
$(this).val($(this).val() + newline + '[' + new Date().formatMMDDYYYY() + '] ' + uname + ': ');
updated = true;
});
});