Html,js Simple save TextArea line wrapping format

Source: Internet
Author: User


Sometimes when we do form submission, we often need to save the HTML tag, but textarea does not save the line-wrapping information, so we need to use JS to save textarea and other HTM tags.
Really let the HTML text box in the form of exchange and other formats remain.
If you need to use, directly copy the following textarea in the format of the line to keep the code is OK, the code is as follows:

<HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312" /><title>Let the HTML text box textarea and other formats with JS reserved</title></Head><Body><formID= "Form1"name= "Form1"Method= "POST"Action=""><textareaname= "Textcontent"cols= "+"rows= " the"ID= "Textcontent"></textarea><BR/><inputtype= "button"name= "Submit"value= "Transform Output"onclick= "outhtml ()" /><inputname= "checkbox"type= "checkbox"ID= "checkbox"value= "checkbox"checked= "Checked" /><label for= "checkbox"style= "COLOR: #F00">Enable conversion output</label></form><DivID= "Out"style= "border:1px solid #F90; padding:10px; background: #FFF8DC; margin-top:10px">Please enter text test with HTML tag in the text box above! </Div><Scripttype= "Text/javascript">/*********************************************************** author Tang guohui, created:2007-12-9 12:30:15****** ****************************************************/functionouthtml () {varGetValue=document.getElementById ("textcontent"). Value;varEndvalue=( (Getvalue.replace (/< (. +?) >/gi,"&lt;$1&gt;"). Replace (/ /gi, "&nbsp;"). Replace(/\n/gi, "<br/>");
/*(1) Escape "<", ">" (2) Change half-width space to &nbsp; (3) Keep line wrapping*/if(document.getElementById ("checkbox"). Checked==true) {document.getElementById (" out"). InnerHTML=Endvalue;}Else{document.getElementById (" out"). InnerHTML=getValue;}}//End outhtml Function</Script></Body></HTML>

This is just an HTML text box textarea in the format with JS to keep the model, you also need to develop to meet your needs, hope that Cenxi website development to share to your content to help you! Reprint please indicate the source, thank you!

Html,js Simple save TextArea line wrapping format

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.