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