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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Location
    england
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow when changing a value of a textfield how do I make \n show up

    when changing a value of a textfield how do I make \n show up instead of make a line break?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Do you mean textarea? Can you give us an example of what you are trying to do?

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Perhaps you mean something like this:

    <textarea cols="40" rows="10" onchange='this.value=unescape(escape(this.value).replace(/%0D%0A/g,"\\n"))'></textarea>

  • #4
    New to the CF scene
    Join Date
    Aug 2002
    Location
    england
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up RE:

    Yeah sorry I do mean a textarea (i keep doing that!).

    what i'm trying to do is make somthing which generates the javascript for a quiz so the user types in his questions and answers then he clicks a button a the Javascript for the quiz appears in the textarea. but when you tell the next area to have a "\n" in it makes a line break but I want the textarea to shoe the "\n" instead of making a line break.

    Hope that makes it clearer

  • #5
    New to the CF scene
    Join Date
    Aug 2002
    Location
    england
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    umm

    thanks for the script John but i don't understand this bit: onchange='this.value=unescape(escape(this.value).replace(/%0D%0A/g,"\\n"))'>

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    It was just an example to show you how it could work. Let me break it down:

    onchange='this.value=unescape(escape(this.value).replace(/%0D%0A/g,"\\n"))'>

    when the value of the textarea changes, escape the value which will basically URL encode the text. Then replace all instances of %0D%0A, which is the line break, with \n. Then unescape everything so the URL encoded text goes back to normal.

  • #7
    New to the CF scene
    Join Date
    Aug 2002
    Location
    england
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    heres an example

    here is an exmple, load this up in your browser and have a look:

    <html>
    <head>
    <title>generator</title>
    </head>
    <script language="JavaScript">
    var txt='hello'+' bye '+'\n hello';
    </script>
    <body>


    <form name='end'>
    <textarea cols="40" rows="10" name='end'>click go</textarea>
    <input type="button" value='go' onClick='this.form.end.value=txt;'>
    </form>
    see the \n makes a line break but I don't want it to I want the textarea to say "hello bye \n hello"
    </body>
    </html>

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try escaping the "n" with an additional backslash:

    \\n

  • #9
    New to the CF scene
    Join Date
    Aug 2002
    Location
    england
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Brillaint

    Thank you very much that has sloved my problem THANK YOU


  •  

    Posting Permissions

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