Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript for adding <br> in textarea

Posted on 1998-01-29
3
Medium Priority
?
934 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
Christian_Wenz earned 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

618 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