/    Sign up×
Community /Pin to ProfileBookmark

How can I strip out a carriage return in a text box?

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 [B]onChange, the text box goes from:[/B]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@CharlesOct 23.2003 — [font=monospace]<!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(/[rln]+/g, ' ')"></textarea></label>

<button type="submit">Submit</button>

</div>

</form>[/font]
Copy linkTweet thisAlerts:
@mh53j_feauthorOct 23.2003 — 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(/[rln]+/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
Copy linkTweet thisAlerts:
@CharlesOct 23.2003 — [font=georgia]What you have there works for me. There must be an error somewhere else on the page. Also,[/font][i]From the HTML 4.01 Specification:[/i]

[b]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.[/b]

[i]http://www.w3.org/TR/html4/struct/tables.html#h-11.1[/i][/quote]
×

Success!

Help @mh53j_fe spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...