Forum Moderators: open

Message Too Old, No Replies

escaping commas and quotes in javascript...

         

mylungsarempty

8:31 am on Sep 1, 2003 (gmt 0)

10+ Year Member



If i'm telling javascript to write to the document, how would i escape a quote so that i can let html affect text, instead of confusing the script?

mylungsarempty

9:29 am on Sep 1, 2003 (gmt 0)

10+ Year Member



this ought to be an easy one guys. . . or can you simply not escape characters in javascript? here's an example of what i'm trying to achieve:

<SCRIPT>
function anything ()
{
return '<TABLE border="0" width="450" cellspacing="9">
<TR><TD style="filter:progid:DXImageTransform.Microsoft.Gradient(
endColorstr='#88AAFF', startColorstr='#FFFFFF', gradientType='0');">
<FONT face="Tahoma" size="1" color="444444">text text text</FONT></TD>
<TD>more text more text</TD></TR></TABLE>'
}
</SCRIPT>

But as i'm sure you can tell, the " ' "'s are messing it all up for me. How can i tell javascript to just ignore all those " ' "'s before the one i need to close the return function?

claus

9:44 am on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:

\"

-i'd think it would work fine.

/claus

g1smd

10:05 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Hide any closing tags like '</td>' that are within document.write statements by either breaking them open '</' + 'td>' or by escaping them <\/td> and the validator will no longer complain about these closing tags. If you break them up, then it is important to break directly after the / and not the middle of a word. Escaping them is a lot cleaner way of doing this though. Every single closing tag will need to be fixed.

Javascript is best done with external .js files, called using:
<script type="text/javascript" language="javascript" src="/path/file.js"></script>

MonkeeSage

10:15 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



JavaScript, like Perl, has two levels of quoting, single quotes ('') and double quotes (""). Why, since it doesn't evaluate variables in either kind? I have no clue. :)

But...it makes it nice because then you don't have to escape...what I mean is, if you need to quote some text with quotes in it, for example, HTML tags...

<a href="blah.htm">Blah</a>

...then you just use the opposite quotes around it...

'<a href="blah.htm">Blah</a>'

...then you only need to scape when you have a string that uses both, like...

'<a href="blah.htm" onclick="alert(\'Blah!\');">Blah</a>'

Jordan