开发者

New Line in textarea problem

Hello all I created a textarea and I can "enter" a new line in it all day but when I submit the box. Its all one continuous sentence. Any thoughts??

<tr id="commentRow">              
         <td>
         You have <strong><span id="commentsCounter">${const['COMMENT_MAX_LENGTH'] - fn:length(commentForm.comment)}</span></strong> characters left.<br/>
            <textarea id="comment" name="comment" rows开发者_StackOverflow社区="2" cols="125" style="width:360px;"
                 onkeypress="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"
                 onkeydown="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"
                 onkeyup="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"></textarea>

                    <a href="javascript:addComment();"><img src="../images/icon_add.gif" border="0" alt="Add"/></a>
        </td>
        <td class="shaded" colspan="1">&nbsp;</td>
        </tr>

is there something I need to add to the jsp??

Hey buddy below this is prior to adding the

<form id="commentForm" name="commentForm" action="" method="post">
<ctl:vertScroll height="300" headerStyleClass="data_table_scroll"      bodyStyleClass="data_table_scroll" enabled="${user.scrollTables}">
<ctl:sortableTblHdrSetup topTotal="false" href="show.whatif_edit_entry?entryId=${entry.entryId}"/>
<table class="data_table vert_scroll_table" style="width:360px;">
    <tr>
    <ctl:sortableTblHdr styleClass="center"  title="Comments" property="comment" type="top">Comments</ctl:sortableTblHdr>    
    <ctl:sortableTblHdr styleClass="center"  title="Created By" property="auditable.createdBy.lastName" type="top">Entered By</ctl:sortableTblHdr>

    </tr>
    <c:forEach var="comments" items="${entry.comments}">


        <tr id="id${comments.id}">
        <td id="comments-${comments.id}" class="wrappable" style="width:360px;" >${comments.comment}</td>

New Line in textarea problem

Then I added the

<tr id="id${comments.id}"> <td id="comments-${comments.id}" class="wrappable" style="width:360px;" ><pre>${comments.comment}</pre></td>

The table then expanded HUGE!!!!!

New Line in textarea problem

any thoughts???


If you want to display data from a textarea as html you will need to convert any \n characters into <br> (or <br /> for XHTML) tags, otherwise they'll show up in your source but not on your page.

Alternatively wrapping the whole thing in <pre></pre> tags will also work as this will treat the text as pre-formatted and display it like a text editor (saving tabs and whitespace).

If you were to output whatever is entered in the textarea into the <td class="shaded"> you'd change that to <td class="shaded" colspan="1"><pre>textarea input displayed here</pre></td>


However you are displaying the submitted data probably isn't taking into account the newline characters that you are submitting. I would see if there are any \r or \n characters to change to new lines "<br />" in HTML.


use this in textarea value to break line to new

\n\n

tested as required

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜