Solved

Javascript for adding <br> in textarea

Posted on 1998-01-29
3
910 Views
Last Modified: 2012-08-14
Is it possible to have a javascript function called
via an Onblur that will insert a <BR> into the value
of a textarea when it encounters a (CR) carriage return?
0
Comment
Question by:trout7
3 Comments
 
LVL 5

Accepted Solution

by:
Christian_Wenz earned 100 total points
ID: 1277884
have a look at this example:

<HTML>
<SCRIPT LANGUAGE="JavaScript"><!--
function remove(str){
 var x = ""
 for (var i=0; i<str.length; i++){
   if (str.charAt(i) == "\n") x += "<BR>"
      else if (str.charAt(i) != "\r") x += str.charAt(i)
 }
 return x
}
//--> </SCRIPT>
<BODY><FORM><TEXTAREA onBlur="this.value=remove(this.value)"></TEXTAREA></FORM></BODY></HTML>

if you have questions, please drop a comment!

      Christian
0
 

Author Comment

by:trout7
ID: 1277885
This rules. - Thanks.
0
 

Expert Comment

by:zirbel_ch
ID: 13800678
It's a nice function!

In a form I have two textareas for which I use this function because i'll print the contens in a new window.

But I would love to make the remove-process somehow in the background, because the resulting single string with all his <br> looks a bit strange for some users.

Is there a way to leave the input-textarea-field untouched, but to write it's content simultaneously in the background to a hidden field, making the remove-process there and print the content-string with his <br> in a new window? The problem I found: There is no "on..."-action possible for a hidden field, right?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 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

17 Experts available now in Live!

Get 1:1 Help Now