Script Categories

Forms >>> Remove Returns.

Converts carriage returns in a string to the tag so that the input can be properly displayed in HTML. Without the script, returns in an input field are not preserved when submitting in a form. Useful for guestbooks or other times when a user's input must be preserved.


Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function ConvertBR(input) {
// Converts carriage returns
// to <BR> for display in HTML

var output = "";
for (var i = 0; i < input.length; i++) {

if ((input.charCodeAt(i) == 13) || (input.charCodeAt(i) == 10)) {
output += "<BR>";
else {
output += input.charAt(i);
return output;
//  End -->
name=message rows=8 cols=50>You may type a message here

Make sure to press the [Enter] key a few times.

That way you will be able to see the

conversion function in action.
<input type=button value="Convert Returns" onClick="this.form.output.value = ConvertBR(this.form.message.value);">
Output:  <input type=text name=output size=50>

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.

Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).