<script language="javascript">
function postComment(){
var f = document.comment;
var thought = f.thought.value;
var url = "process_comments.php";
var postStr = "thought="+ thought;
var ajax=new XMLHttpRequest();
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(postStr);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
var errorMessage=ajax.responseText;
document.getElementById('errorMessage').innerHTML=errorMessage;
}
}
}
</script>
<div class="py-5">
<form name="comment" method="post" action="" class="form-signin">
<h3 class="h4 mb-3 font-weight-normal">Type and save. You know the drill.</h3>
<?php
/*
if ($thought_error === true) {
echo "<p class='text-danger' id='errorMessage'></p>";
}
*/
?>
<textarea class="form-control" type="text" id="thought"name="thought" rows="3" maxlength="254" placeholder="Do not enter more than 254 characters!" required></textarea>
<div class="mx-auto py-4">
<button class="btn btn-lg btn-primary w-25 right" type="submit" onClick="postComment()">Save</button>
<button class="btn btn-lg btn-warning w-25" type="reset">Clear</button>
</div>
</form>
</div>
<p class='text-danger' id='errorMessage'></p>