dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

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

  1. #1
    Join Date
    Mar 2003
    Posts
    11

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

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    <!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>
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Mar 2003
    Posts
    11

    Charles, I tried your suggestion - am getting JS errors

    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

  4. #4
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    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
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles