I\'m having some trouble whenever I want to add some text to my div tag, here\'s my code:
It is because you are submitting the form.
Quick fix:
to
In addition, you are able to prevent the default action of an input. Basically telling the browser the you are going to handle the action with preventDefault:
function writeComment(e) {
var comment = document.forma.commentUser.value;
alert(comment);
document.getElementById('comments').innerHTML = comment;
e.preventDefault();
return false;
}