When I press the return key to start a new line for the post, the result auto-ignore the return key. I wondered what the most common way of making the output actually starts wi
No. The <br />
is not at all present there. There's \r\n
. So you need to use:
$comment = nl2br($comment);
To convert all the new lines to break in your PHP code.
Im replying to this because your other question was marked duplicate.
By replacing 2 of your <div>
with these,
<form>
<textarea name="comment_box" id="comment_box"></textarea>
<input id="post_comment" class="comment_leg" type="submit" value="Post">
</form>
It is able to capture the space by changing your script to capture the textarea with the method .val()
var txt = $("textarea#comment_box").val();
if(txt){
$.post("commenttest.php", {txt: txt}, function(result){
$("div[name=commentsubmit]").prepend(result);
$("textarea#comment_box").val();
});
}
To have it printed with the line break, in your commenttest.php, insert this before you echo, which is what you have tried but didnt work from your duplicate post or recommended from an answer.
$comment = nl2br($comment);