Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@salcode
Created June 9, 2016 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salcode/5158b37208887f69e558db46182a84a3 to your computer and use it in GitHub Desktop.
Save salcode/5158b37208887f69e558db46182a84a3 to your computer and use it in GitHub Desktop.
jQuery JavaScript to populate a blank comment with an Automated Comment. This is being done on the client side because on the server side there is no filter available before the check for an empty comment body.
jQuery('#commentform').on('submit', function() {
var $comment = jQuery('#comment');
if ( '' === $comment.val().trim() ) {
$comment
.css({'color':'#fff'})
.val( 'Automated Comment: ' + Math.floor( new Date().getTime() / 1000 ) );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment