Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

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

843840Aug 8 2007 — edited Aug 8 2007
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 :
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:
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 5 2007
Added on Aug 8 2007
2 comments
2,199 views