Line breaks in string containing Javascript

T

Travis Pupkin

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.
 
A

Adrienne Boswell

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.
 
M

Mark Schupp

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.
 
H

Hal Rosser

Travis Pupkin said:
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"
);
 
T

Travis Pupkin

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top