Skip to content Skip to sidebar Skip to footer

Javascript | Save Textarea Value With Line Breaks

I have a code where it saves multiple textarea values in a text file. However, it does not display the line breaks I indicated after saving it. It only identifies the line breaks w

Solution 1:

The problem stems from the fact that line breaks (\n) are not the same as HTML <br /> tags.

Try this:

var text = document.forms[0].txt.value;
text = text.replace(/\n\r?/g, '<br />');

Edit, try this as the js:

var text = document.forms[0].txt.value;

if (text === true) { text = text.replace(/\n\r?/g, '<br />'); } 

varTestVar = newArray(i); 
var i = 0;
functionsave()
{
TestVar[i] = document.getElementById("text1").value + "/n" + document.getElementById("text2").value;
mydoc = document.open();
mydoc.write(TestVar);
mydoc.execCommand("saveAs",true,"TicketID.txt");
mydoc.close();
}

Post a Comment for "Javascript | Save Textarea Value With Line Breaks"