Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Jul 2003
    Location
    Dallas, Texas
    Posts
    3
    Member #
    1999
    OK, I give up. Anybody know why a javascript alert will ignore line feed characters if the information is coming from a hidden field on a form?

    Here is some sample code. Of course, the real code I am using is a lot more extensive.

    <html>
    <head>
    <title>
    Test Alert
    </title>
    </head>
    <body>
    <%
    errorstring = "This is a test string for" & "\r\n" & "the r n function"
    Response.Write("<form name=data_in method=post action="""">")
    Response.Write("<input type=hidden name=errorstring value=""" & errorstring & """>")
    Response.Write("</form>")
    %>

    <Script language="JavaScript">

    JavaMsg(document.data_in.errorstring.value)
    JavaMsg("This is a test string for" + "\r\n" + "the r n function")

    function JavaMsg(MyMsg){
    alert(MyMsg);
    }
    </script>

    </body>
    </html>

    Thanks for any help!!!!!!!!!!
    Lee

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Try just:
    Code:
    alert("This has a \nnewline in it");
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    Junior Member
    Join Date
    Jul 2003
    Location
    Dallas, Texas
    Posts
    3
    Member #
    1999
    Yes, it will work if you place a text string within the parens. That is not the problem.

    In the example I provided, you will note that it calls the routine twice. The first one passes a value from the form and it does not work. The second passes a string and it does work. It will work on the second attempt with either /r/n OR /n. It will fail on the first attempt regardless.

    It is a most curious problem.

    Thanks,
    Lee

  5. #4
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    It's an attribute of HTML...try using <br /> or the entity for a line break (
    , maybe?) instead. As you know, HTML ignores most whitespace.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  6. #5
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    I tried changing this line:

    [minicode]errorstring = "This is a test string for" & "\r\n" & "the r n function"[/minicode]
    to:
    [minicode]errorstring = "This is a test string for" & "& # 10" & "the r n function"[/minicode]
    (remove the spaces between &,#,10) and it worked for me. The reason being, I think, is because when being written as a form value, the \r\n characters get rendered as raw HTML, and not as the return and new line characters you want them to. & # 10 is the ASCII value for a new line, or line feed (ASCIITable.com) and upon being written as raw html, it still retains its character value.

    That make a whole lot of sense ?

    I also changed the Response.Write's to document.write's because I was getting
    ERROR: Object required 'Response'
    and I don't really know ASP/VBScript to figure out why I was getting that.

    I'll u/l the file for you to try out.
    - Brian

  7. #6
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Response.write appends to the outputted HTML contents that ASP generates
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  8. #7
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    That's what I thought, I just don't have ASP installed on my comp and I figured rleerich could make the modifications to that if (s)he needed.
    - Brian

  9. #8
    Junior Member
    Join Date
    Jul 2003
    Location
    Dallas, Texas
    Posts
    3
    Member #
    1999
    Yes, worked.....

    Thanks.

    The real problem with the way I was doing it is that the string that was passed to the javascript routine was not recognized as a javascript string (I guess there is a difference between vbscript strings and javascript strings).

    All I had to do in the javascript routine was to replace /r/n with /r/n (the same literal) and it worked....

    Something new everyday!!!!!!!!!!


Remove Ads

Posting Permissions

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

Search tags for this page

alert javascript linefeed
,

alert linefeeds

,
alerts with linefeed
,
java alert line feed
,

javascript alert line feed

,
javascript line feed
,

javascript linefeed

,

javascript linefeed alert

,
javascript linefeed in text string
,
line feed javascript alert
Click on a term to search for related topics.
All times are GMT -6. The time now is 08:30 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com