Read new line from textarea

new line in textarea; javascript
new line in textarea jquery
how to detect new line in textarea
textarea enter new line
html textarea new line
php save textarea with line breaks
php new line not working
add newline in textarea

I have a web application built. I am trying to fetch the text entered in form:textarea. I want to read the text entered by the user in the same format. Example if the user enters:

hi!
How
Are
you?

I am getting the result as hi! How Are You?, the new lines are missed.

Here is my code sample:

JSP:

 <form:form id="addRssFeed" modelAttribute="rssFeed" action="apiTextContent?mode=addNew&page=rssFeeds" enctype="multipart/form-data" method="post">
          <div class="form-group" style="width: 392px; ">
            <div class="form-row">
              <div >
                 <form:label path="inputTextFiled1" for="tile">Title: </form:label>
             <form:input  path="inputTextFiled1" autocomplete="off" class="form-control" id="title" type="text" placeholder="Enter the title to the Feed"/>
              </div>
              </div>
              <div class="form-row">
              <div >
               <form:label  path="inputTextFiled2" for="content">Content: </form:label>
               <form:textarea path="inputTextFiled2" class="form-control" style="width: 200%; height: 200px;" id="encJs" placeholder="Enter the body of Feed"></form:textarea>

              </div>
            </div>
             <div class="form-row">
              <div >
              <input name="file" id="fileToUpload" type="file" onchange="validateImage()"/>
              </div>
            </div>
              <div >
<%--       <p><form:input name="file" id="fileToUpload" type="file" onchange="validateImage()"/></p> --%>  <p id="message"></p></div> 
          </div>
          <a href="#" onclick="#">Show Preview </a>
          <form:button class="btn btn-primary btn-block"  id="Publish" style="width: 25%;margin: 0px auto;">Publish</form:button>

        </form:form>

ApiText.java

    private String inputTextFiled1;
    private String inputTextFiled2;

--- getters and setters---

Service

public String convertToImage(CommonsMultipartFile file, ApiTextModel apiTextModel) throws IOException {

        StringBuffer imageString = new StringBuffer("");
        String html= null;

        if(file.getSize() !=0){
             File convFile = new File( file.getOriginalFilename());
             file.transferTo(convFile);

            BufferedImage src;

            src = ImageIO.read(convFile);

            BufferedImage image = toBufferedImage(src);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write(image, "png", baos);

            String data = DatatypeConverter.printBase64Binary(baos.toByteArray());
            imageString.append("<img  style=\"display:block; height: 300px; margin-left: auto; margin-right: auto;\"  src='data:image/png;base64," + data+"'>");

        }

            html =  "<html><body> "+
                    "<h2 style=\"text-align: center;font-size: 49px;\">"+apiTextModel.getInputTextFiled1() +" </h2> "+ imageString.toString() +
                    "<div style=\"font-size: 25px;\">"+apiTextModel.getInputTextFiled2() +"</div></body></html>";
            System.out.println(imageString);
        return html;

    }

Please suggest if i need to change my approach or try something else.


Basically a white space character(which includes new line chr too) is converted by the HTML to single space. You will need to write onChange method for the textarea to convert the new line char to either <br> or <p>. By this you will be able to hold the property of new line.

Please review this answer: https://stackoverflow.com/a/29575181/3465242

How to detect “shift+enter” and generate a new line in Textarea , How to read a local text file using JavaScript? When and By default, whenever we press “enter” or “shift+enter” it creates a new line in the text area. So, to only  One idea is to split the getText() results by line breaks, using the regular String.split() method. SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6 How To Ask Questions How To Answer Questions


Have you tried br tag? try using br tag where you are printing the result.

How to add line breaks to an HTML textarea?, How to read a local text file using JavaScript? How to Toggle an Element Class in JavaScript ? ES6 | Classes · When and why to 'return false' in JavaScript? How  The LF character does not render to a new line or line break in HTML. The TEXTAREA renders LF as a new line inside the text area box. share | improve this answer | follow | | | |


Looks like you display it as HTML, please try:

String text = text.replace("\n", "<br>");

[Solved] How to recognize the new lines from web text area , TextArea uses carrage-return('\r'), line-feed('\n') style chars for line If will preserve the line break in the markup to make it easier to read. the  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.


nl2br - Manual, nl2br — Inserts HTML line breaks before all newlines in a string Rather, it inserts a <br> tag before each newline, but it still preserves the newlines themselves! I just spent a whole day trying to figure out why my textarea $_​POST was not  You will need to write onChange method for the textarea to convert the new line char to either <br> or <p>. By this you will be able to hold the property of new line. By this you will be able to hold the property of new line.


Rendering text with newline characters in HTML correctly, The textarea element does honor newlines; when its contents are fetched When that value is read from disk later, it will contain these newline  The JTextArea class provides a component that displays multiple lines of text and optionally allows the user to edit the text. If you need to obtain only one line of input from the user, you should use a text field. If you want the text area to display its text using multiple fonts or other styles, you should use an editor pane or text pane. If


multi-line text will not do line break in view · Issue #7781 · angular , However the result just display a text string, no line break. br is just ignored. Please fix! I found that "\n" can break line in textarea,but not in <div [innerHTML​]="text"></div>. I think I must replace I am used to asp.net, Anguar 2 is new to me. Read more about our automatic conversation locking policy. The assignment statement changes the contents of the TextArea and the last line sets the first word in the new text to Bold. To display the styled text, you can assign the styled text object to the TextArea's StyledText property. Any programmatic changes to style attributes that you make while the styled text is displayed will update immediately.