Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Preserve blank lines when add multiple lines of text to a cell

Thread Tools

Preserve blank lines when add multiple lines of text to a cell

Cah Sableng
Posts: n/a
I have a function which adds multiple lines from a textarea to a cell
within table. Code follow. It works fine for me, except for blank
lines. The blank lines become stripped. How to preserve those blank


<title>Add Row (Multiple Line)</title>
<script type="text/javascript">
function addRow(idTbl)
var frm,tbl,re,oldStr,newRow,newCell,matched;
frm = document.forms['formMain'];
tbl = document.getElementById(idTbl);
re = /([^\r\n]*)([\r\n]+)/;
oldStr = frm.elements['taDesc'].value;

newRow = tbl.tBodies[0].insertRow(-1);
newCell = newRow.insertCell(-1);
while (re.test(oldStr))
matched = re.exec(oldStr);
oldStr = oldStr.replace(re, "");
newCell.appendChild(document.createTextNode(matche d[1]));
//alert("'" + matched[2] + "'");
newCell.appendChild(document.createTextNode(oldStr ));
<style type="text/css">
td {
padding:2px 5px;
border:1px solid black;

<form name="formMain">
<textarea rows="4" cols="30" name="taDesc">Line 1
Line 2
Line 3</textarea><br>
<input type="button" name="add" value="Add" onclick="addRow('tblA');">
<table id="tblA">

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple lines of text in a cell mcilwrk Microsoft Certification 1 04-22-2008 03:06 PM
To delete few lines and add few lines at the end of a text file using c program Murali C++ 2 03-09-2006 04:45 PM
add blank lines after word MAC (sed/awk or perl??) NNTP Perl 2 04-07-2004 06:04 AM
Blank Data Fields, How2 Preserve Tbl Columns?, use &nbsp; Robert Kattke XML 0 12-31-2003 08:32 PM
FileUtils - :preserve does not preserve mtime of directories on Windoze Grzegorz Chrupala Ruby 2 06-30-2003 07:38 AM