Click to See Complete Forum and Search --> : How can I strip out a carriage return in a text box?


mh53j_fe
10-23-2003, 06:44 AM
To support reporting, I want to strip out all carriage returns in my text boxes. I wrote the following code that does not work:

//If carriage return found, remove it.
function isNewLine( field )
{
var l_field_value = field.value;
var l_field_str = l_field_value.toString();
l_field_str = l_field_str.split("\n");
field.value = l_field_str.join(" ");
return true;
}//end function isNewLine()

onChange, the text box goes from:
This is a test of a carriage
return
to this:
This is a test of a carriage
return.

Note that the code does find the newline. I want the code to strip it out and wrap the text around the box.

Thanks in advance for your help. I really do appreciate the help from this forumn!

Dave onChange, the text box goes from:

Charles
10-23-2003, 07:01 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
textarea {display:block}
-->
</style>

<form action="">
<div>
<label>Comments<textarea onchange="this.value = this.value.replace(/[\r\l\n]+/g, ' ')"></textarea></label>
<button type="submit">Submit</button>
</div>
</form>

mh53j_fe
10-23-2003, 07:21 AM
Charles,

I tried your suggestion. Here is my code:

<td><textarea tabIndex="1" name="TITLE" value=$TITLE wrap="virtual" cols="65" rows="2"
onChange="this.value = this.value.replace(/[\r\l\n]+/g, ' ')">
$TITLE</textarea> </td>

I am getting a JS error that IE is saying comes from about 40 lines above this code. This code worked without this addition; therefore, I am thinking there is something wrong here. Thanks again for your help.

Dave

Charles
10-23-2003, 07:26 AM
What you have there works for me. There must be an error somewhere else on the page. Also,From the HTML 4.01 Specification:
Tables should not be used purely as a means to layout document content as this may present problems when rendering to non-visual media. Additionally, when used with graphics, these tables may force users to scroll horizontally to view a table designed on a system with a larger display. To minimize these problems, authors should use style sheets to control layout rather than tables.
http://www.w3.org/TR/html4/struct/tables.html#h-11.1