Solved

Javascript for adding <br> in textarea

Posted on 1998-01-29
3
915 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
innerHTML 7 34
I thought I had multiple sliders on one page working properly . . . I don't. 10 16
Filktering Alphabetically 8 30
Copying table data to one another 15 29
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

861 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