Howto populate a Multi-line textbox using javascript and vbCrLf

Posted on 2009-02-19
Last Modified: 2012-05-06

I need to poulate a multi-line textbox using document.getElementById("blah").value or document.getElementById("blah").innerHTML

However, my source has <br> tags included in it which also get placed into the textbox.

Can someone provide an example of poupulating the textbox and keeping the carriage returns without displaying <br> tags ?

Thank you,

Question by:nickrawlins
    1 Comment
    LVL 15

    Accepted Solution

    try the below for a simple find and replace function to replace <br> with \n (carriage returns)
    <script type="text/javascript">
    function populatetext(){
    	var text='Hello <br><br>my name is tom';
    	var area=document.getElementById('blah');
    	var re = new RegExp ('<br>', 'gi');
    	var text = text.replace(re, '\n');	
    <body onLoad="populatetext()">
    <form name="testForm">
    <textarea id="blah"></textarea>

    Open in new window


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now