Carriage return in <textarea> - how do I check for and remove it???

This is a discussion on "Carriage return in <textarea> - how do I check for and remove it???" within the JavaScript Forum section. This forum, and the thread "Carriage return in <textarea> - how do I check for and remove it??? are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 8th, 2007, 13:38
Junior Member
Join Date: Feb 2007
Location: USA
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Question Carriage return in <textarea> - how do I check for and remove it???

I have an html form that has a <textarea> element for user input. I work mainly with Java and some JavaScript. Since carriage returns are permitted in a <textarea> element, upon retrieving the value submitted, my Java and/or JavaScript variables contain carriage returns as well, making the values incomplete.

For Example :
Code: Select all
String dataSubmitted = request.getParameter("formInput");
              
<script language="JavaScript">
 var textValue = "<%=dataSubmitted%>";
....//do other stuff
</script>
When I view the source of my JSP page, the above statement of code looks like this:
Code: Select all
var textValue = "This is some text that 
I submitted with a carriage return";
I'm putting the text submitted through this form into a mysql database, and when I pull up the values I find that it has recorded the carriage return as well. There is an actual symbol representing a carriage return in the db field.

What I'd like to do is use some Java code to go through each character of the String and find and remove the carriage return, perhaps replacing it with an empty space instead. But how do I check for a carriage return in a String variable?

Also, is there a way to use JavaScript to alert the user when the carriage return button is pressed when they're in the <textarea>?

Any input is appreciated,
Thank You,
-Love2Java
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 8th, 2007, 15:58
Junior Member
Join Date: Feb 2007
Location: USA
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Talking Re: Carriage return in <textarea> - how do I check for and remove it???

I received help from a forum member on another forum I'm a member of, he/she showed me how to accomplish what I described above.
Here it is for anyone else who had this problem as well.

Code: Select all
String checkedLine = request.getParameter("formInput").replaceAll("\r\n"," ");
This replaces a carriage return with an empty space. Alternatively, you can replace the carriage return with anything, I'm going to use the html break element myself.

As for the JavaScript portion of my post, this can be accomplished by using the following:
Code: Select all
<textarea onkeypress="if (event.keyCode == 13) alert('You pressed the return button.'); return false;"></textarea>
return false; prohibits the carriage return from being inserted, if you leave that out, the carriage return will insert.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
carriage return, textarea

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] breaklines in textarea andyg PHP Forum 2 Apr 10th, 2008 13:31
Textarea errors pritmadlani Web Page Design 2 Apr 3rd, 2008 20:58
transorm xml in textarea scribble Other Programming Languages 0 Nov 29th, 2006 23:18
Controlling Textarea Size With CSS xKillswitchx Web Page Design 2 Mar 4th, 2006 06:11
return from db benbramz Classic ASP 5 Jun 19th, 2005 18:29


All times are GMT. The time now is 06:14.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42