Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

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

 
 
Cah Sableng
Guest
Posts: n/a
 
      04-23-2007
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
lines?

TIA.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html>
<head>
<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]));
newCell.appendChild(document.createElement('br'));
//alert("'" + matched[2] + "'");
}
newCell.appendChild(document.createTextNode(oldStr ));
}
</script>
<style type="text/css">
td {
padding:2px 5px;
border:1px solid black;
}
</style>
</head>

<body>
<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');">
</form>
<table id="tblA">
<tbody>
</tbody>
</table>
</body>
</html>

 
Reply With Quote
 
 
 
Reply

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



Advertisments