I can not break the line using JavaScript

0

Good morning, I'm having some difficulty trying to break a line using javascript's [b] \ n [/ b]. The code is working perfectly, what happens is that at the time of displaying, it looks something like this:

My nick: Vinicius How I discovered the server: YouTuben I want to play because:

Type \ n is not breaking the line, but it appears there at the end of every string I put in, what's going on?

<script>
    $(function () {
        $('[name="post"]').click(function () {
            var nick = $('#field0').val();
            var descobriu = $('#field1').val();
            var motivo = $('#field2').val();
            $('input[name="subject"]').val('[ Whitelist] ' + nick + ' ');
            $('input#message').val('[b]Meu nick:[/b] ' + nick + ' <br>[b]Como descobri o servidor:[/b] ' + descobriu + ' \n[b]Eu quero jogar porque:[/b] ' + motivo);
        });
    });
</script>
    
asked by anonymous 27.08.2016 / 17:33

2 answers

1

Instead of putting in an input, set a <p id="paragrafo"> <p> then you use your call by changing the element id:

 $('paragrafo').val('[b]Meu nick:[/b] ' + nick + ' <br>[b]Como descobri o servidor:[/b] ' + descobriu + ' \n[b]Eu quero jogar porque:[/b] ' + motivo);
    
25.08.2017 / 18:28
3

I do not see much sense in wanting to use line wrap in input . In this case, the appropriate would be textarea .

Just use \n to break the lines, see it working:

var nick = 'XYZ';
var descobriu = 'por acaso';
var motivo = 'achei legal';

$('#message').val('[b]Meu nick:[/b] ' + nick + '\n[b]Como descobri o servidor:[/b] ' + descobriu + ' \n[b]Eu quero jogar porque:[/b] ' + motivo);
#message {width:80%}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script><textareaid="message"></textarea>
    
27.08.2016 / 18:17