Halloween

some text is entered into textarea. Next is a button with a js-function, when clicked, the text is processed and returned to the textarea. The problem is that the text is returned without line breaks. How to save line breaks?

For example, such a function. Everything works, but the result is returned in one continuous line.

function addcomma(comma) { var str = document.getElementById('comma').value.replace('\r', ''); var result = str.split('\n'); var i = 0; while (i < result.length) { document.getElementById('comma').value = result[i] + ','; i++; } } 

    2 answers 2

    document.getElementById('comma').value = result.join(',\n'); Not okay?

    • rolls, thanks :) - Irinkes
    • more accurate: document.getElementById ('comma'). value = result.join (', \ n'); - Irinkes
    • Yes exactly). - ling
     var str = document.getElementById('comma').value.replace('\r', ''); var result = str.split('\n'); 

    and then what's the problem? First you mow everything in the string r and then you want their split somehow illogical.