View Full Version : Javascript Strings (please help!)

05-26-2005, 04:01 PM
Hi, I'm trying to pass a string into a function, but can't get around the way that the string has to be passed within quotes. For example, I have:

somefunction("Paul said, "This isn't a great example, but it works."");

Obviously the string will terminate early at the first ", and if I change the surrounding quotes to ', the string will also terminate early. Now, I'm pretty dumb but I do realize that I could just use an escape character to get around this problem, but the entire string
Paul said, "This isn't a great example, but it works."
Is brought in from a database (which is put in by a user who would know nothing about programming). Is there any way to get around this??? I know in PHP they have some kind of special way to notate a string without quotes (like <<< DOC string goes here >>>) or something like that. I tried to write a function that will replace the user-input ' and " with \' and \", but I can't even pass *that* function the string because of the same problem.
Any help?

05-26-2005, 04:23 PM
somefunction('Paul said, "This isn't a great example, but it works."'); :thumbsup:

Eternity Angel
05-26-2005, 06:41 PM

whatever("<? echo addslashes($dbdata); ?>");

This was never a JS problem. :-p