Solved

Javascript for adding <br> in textarea

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
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'…
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…

706 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

16 Experts available now in Live!

Get 1:1 Help Now