HTML:
<div class="mb-3">
<label for="comment" class="form-label">Comments</label>
<textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
</div>
javascript:
let comment = $('textarea.msg').val()
alert(comment);
and then PHP:
echo $_POST['comment'];
echo isset($_POST['comment']);
echo trim($_POST['comment']) != '';
Here, the Response tab in Network tab of Firefox Inspect shows nothing for the echo commands in PHP. I am not sure why the textarea input hi is not shown hence not inserted.
Even for the javascript alert of comment variable, I get this:
let comment = $('#comment').val().trim();
Credits to Chris Haas.
<div class="mb-3">
<label for="comment" class="form-label">Comments</label>
<textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
</div>
id is unique in the HTML and with jquery it would be easier to target the element you want. For class we use $(.<classNAME>) while for id we use $(#<id_Name>)
Your Case, $('#comment').val()