Solved

Javascript for adding <br> in textarea

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…
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…

911 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

21 Experts available now in Live!

Get 1:1 Help Now