Line breaks in string containing Javascript

Discussion in 'ASP General' started by Travis Pupkin, Dec 9, 2004.

  1. Hi,

    I'm putting together a site to allow someone to add content to a DB
    through a text area form, and then display it on the web. Pretty basic.

    The problem I'm having is that they need to add snippets of javascript,
    but by the time its displayed on the page, there have been extra
    linebreaks added, breaking the javascript code.

    Replace(string, vbCrLf,"") won't work because that removes all
    linebreaks. Is there a way to preserve the original linebreaks as
    submitted to the DB in the first place?

    Thanks.
    Travis Pupkin, Dec 9, 2004
    #1
    1. Advertising

  2. Gazing into my crystal ball I observed Travis Pupkin <>
    writing in news::

    > Hi,
    >
    > I'm putting together a site to allow someone to add content to a DB
    > through a text area form, and then display it on the web. Pretty basic.
    >
    > The problem I'm having is that they need to add snippets of javascript,
    > but by the time its displayed on the page, there have been extra
    > linebreaks added, breaking the javascript code.
    >
    > Replace(string, vbCrLf,"") won't work because that removes all
    > linebreaks. Is there a way to preserve the original linebreaks as
    > submitted to the DB in the first place?
    >
    > Thanks.
    >


    Just thinking off the top of my head, you could include another textarea
    control for them to add the javascript, and then when you get _that_
    field, you can do the replace.

    Or, you could look for the beginning and end of the script tags, and
    replace within them.

    --
    Adrienne Boswell
    Please respond to the Group so others can share
    Adrienne Boswell, Dec 9, 2004
    #2
    1. Advertising

  3. Travis Pupkin

    Mark Schupp Guest

    The text area should send the linebreaks that are entered.

    Show your database update code and the code you use to send the content back
    to the client.

    --
    --Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com

    "Travis Pupkin" <> wrote in message
    news:...
    > Hi,
    >
    > I'm putting together a site to allow someone to add content to a DB
    > through a text area form, and then display it on the web. Pretty basic.
    >
    > The problem I'm having is that they need to add snippets of javascript,
    > but by the time its displayed on the page, there have been extra
    > linebreaks added, breaking the javascript code.
    >
    > Replace(string, vbCrLf,"") won't work because that removes all
    > linebreaks. Is there a way to preserve the original linebreaks as
    > submitted to the DB in the first place?
    >
    > Thanks.
    Mark Schupp, Dec 9, 2004
    #3
  4. Travis Pupkin

    Hal Rosser Guest

    "Travis Pupkin" <> wrote in message
    news:...
    > Hi,
    >
    > I'm putting together a site to allow someone to add content to a DB
    > through a text area form, and then display it on the web. Pretty basic.
    >
    > The problem I'm having is that they need to add snippets of javascript,
    > but by the time its displayed on the page, there have been extra
    > linebreaks added, breaking the javascript code.
    >
    > Replace(string, vbCrLf,"") won't work because that removes all
    > linebreaks. Is there a way to preserve the original linebreaks as
    > submitted to the DB in the first place?
    >
    > Thanks.


    one way - set the "wrap" attribute of the textarea to "hard" and it
    sends the data exactly as it appears in the textarea.
    <textarea wrap="hard" name="codeStuff">
    --- or--- tell user to enter semicolons after every javascript command
    ** this will work**
    document.write("hello"); var myVar = 10; document.write(myVar)
    **this will not work***
    document.write("hello") var myVar=10 document.write(myVar) //'**(no
    semicolons)
    **this will work** (should include some line breaks)****
    document.write(
    "hello"
    );




    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.807 / Virus Database: 549 - Release Date: 12/7/2004
    Hal Rosser, Dec 9, 2004
    #4
  5. In article <Ju4ud.65140$>,
    says...
    >
    > "Travis Pupkin" <> wrote in message
    > news:...
    > > Hi,
    > >
    > > I'm putting together a site to allow someone to add content to a DB
    > > through a text area form, and then display it on the web. Pretty basic.
    > >
    > > The problem I'm having is that they need to add snippets of javascript,
    > > but by the time its displayed on the page, there have been extra
    > > linebreaks added, breaking the javascript code.
    > >
    > > Replace(string, vbCrLf,"") won't work because that removes all
    > > linebreaks. Is there a way to preserve the original linebreaks as
    > > submitted to the DB in the first place?
    > >
    > > Thanks.

    >
    > one way - set the "wrap" attribute of the textarea to "hard" and it
    > sends the data exactly as it appears in the textarea.
    > <textarea wrap="hard" name="codeStuff">
    > --- or--- tell user to enter semicolons after every javascript command
    > ** this will work**
    > document.write("hello"); var myVar = 10; document.write(myVar)
    > **this will not work***
    > document.write("hello") var myVar=10 document.write(myVar) //'**(no
    > semicolons)
    > **this will work** (should include some line breaks)****
    > document.write(
    > "hello"
    > );
    >
    >
    >


    Thanks for the tips. I'm beginning to think that it's the code itself
    that is faulty, and not the way it's being submitted by the form.
    Travis Pupkin, Dec 10, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PJ
    Replies:
    1
    Views:
    515
    Sasha Shevelev
    Aug 4, 2003
  2. bernadou

    Force multi line field value to output with line breaks?

    bernadou, Jan 22, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    345
    bernadou
    Jan 23, 2006
  3. Bob Hatch
    Replies:
    3
    Views:
    191
    Brian Candler
    Feb 1, 2011
  4. Marek Stepanek
    Replies:
    12
    Views:
    401
    Peter J. Holzer
    Sep 2, 2006
  5. alice
    Replies:
    19
    Views:
    249
    alice
    Mar 24, 2007
Loading...

Share This Page