Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Putting newline in form input

    Anyway to put in a newline or something to stop my output from creating a long unwrapped line? I want to make some function onsubmit where it forces a newline character after 10 characters. I seem to have a problem with my input form where it doesnt wrap after I enter the data and long sentences force my output box to look like a rectangle.



    Here is what is happening:

    Long sentence keeps going and going where it extends my output box too long.

    I need it to wrap in my output such as:

    Long sentence keeps going and going
    where it extends my output box too long.


    Here is my html form part where I need to use a form input for my entry:

    <TABLE BORDER=1 CELLSPACING=0 CELLPADDING=3>
    <form action="mypage.html" method=post>
    <TR>
    <TD>
    <TH>Heading</TH>
    <TD><input name="heading" type="text" size=30></TD>
    </TR>
    </form>
    </table>

    This is in a calendar script and I cant use <textarea> so I was hoping to make a function to force newline after 10 characters.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <input name="heading" type="text" size="10" maxlength="30">

    Use size to control how large the input field is, use maxlength to control the maximum number of characters that the field can contain.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks I thought of that but need it to be able to handle sentences. Any other suggestions. I still want to try and put a newline in there and force it to break after 10 characters.

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This seems to work...
    Code:
    <html>
    <head>
    <title>test</title>
    
    <script type="text/javascript">
    
    function forceNewlines( ta, lineLen )
    {
    	var r = new RegExp( "(.{" + lineLen + "})$", 'g' );
    	ta.value = ta.value.replace( r, "$1\n" );
    }
    
    </script>
    
    </head>
    
    <body>
    
    <form>
    	<textarea rows="6" cols="40" onkeydown="forceNewlines( this, 10 )"></textarea>
    	<input type="reset" value="clear" />
    </form>
    
    </body>
    </html>
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I will give it a try. I hope I can use it with "onsubmit" instead of "onkeydown".


  •  

    Posting Permissions

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