We help IT Professionals succeed at work.

Howto populate a Multi-line textbox using javascript and vbCrLf

nickrawlins
nickrawlins asked
on
Medium Priority
814 Views
Last Modified: 2012-05-06
Hi,

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,

Nick
Comment
Watch Question

CERTIFIED EXPERT
Commented:
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');	
	area.value=text;
	
 }
</script>
 
<body onLoad="populatetext()">
<form name="testForm">
<textarea id="blah"></textarea>
</form>
</body>

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.