I have a textarea box where the user types in a message then it outputs into a paragraph markup.
I am successful capturing the text but cannot seem to capture the line breaks.
heres my fiddle
Ideally a string substitution such as <br/> or \n is what i was looking for.
any help would be appreciated, thanks.
var txtBox = $('#myTextArea');
var txt = txtBox.val();
txtBox.keyup(function(){
txt = txtBox.val();
$('p.msg').html(txt);
});
txtBox.keydown(function (e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 13) {
$('p.msg').append('<br />');//ApplyLineBreaks(txt);
}
});
and the markup
<textarea id="myTextArea" class="form_0" name="Enter your message" type="text"></textarea>
<p class="msg" style="text-align: center;">msg here</p>
You can do this with just the keydown event:
http://jsfiddle.net/NJwhC/3/
The
setTimeoutis important, it allows thethis.valueto be populated before accessing it.