Javascript - Populating a field with paragraph

3

I'm developing a javascript to populate a text box, however I came across a situation that is generating me difficulty. I need popular with this message for example:

TEST

TEST

TEST

But I can not bring row breaks when I populate the field, I tried with /n,<br>, </ br>, vbCrLf , but I did not succeed. Someone could help me.

Note that my textbox in html looks like this:

<td colspan="2">
            <textarea id="teste" class="CaixaTexto" runat="server" style="width: 600px;
                height: 90px;" cols="97" rows="5"></textarea>
        </td>

Att,

    
asked by anonymous 28.08.2015 / 15:30

2 answers

1

Uses .replace(/\r?\n/g, '<br />') , example:

  var txtBox = $('textarea');
txtBox.keydown(function(e){
    var that = this;
    setTimeout(function(){
        var html = that.value.replace(/\n/g,"<br/>");
        $("div").html(html);
    },10);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea></textarea>
<div>
    
28.08.2015 / 15:37
1

You said that you tested /n , when in fact it should be \n or \n\r .

    
28.08.2015 / 15:52