mattastic — 2010-07-20T05:24:31-04:00 — #1
Is there a way to use them in strings?
Can I search for them and replace them with an ascii value or silimar somehow?
Thanks in advace
autisticcuckoo — 2010-07-22T01:18:41-04:00 — #2
I don't understand.
If it's from an input field it's already a string!
Why should that cause an error (unless
homepage is undefined)?
When asking for help online it's always a good idea to be as explicit as possible about what you're trying to do, and why. Providing code examples of existing code also helps. I don't quite understand what you are trying to do, or how.
mattastic — 2010-07-21T04:49:39-04:00 — #3
Thanks for your reply.
Its from a user input field so I'm not sure where the special chars will be and what they are.
For example this code causes an error:
homepage += "example - example"
autisticcuckoo — 2010-07-21T01:48:49-04:00 — #4
What special characters? If you want to include a character that you cannot input directly from your keyboard, or cannot be represented using the character encoding you use, you can use escape notation.
Octal escape notation:
var copyright = "\\251 2010";
Unicode escape notation:
var copyright = "\\u00a9 2010";
var copyright = "© 2010";
var s1 = "My \\"new\\" car";
var s2 = 'Jane\\'s car';
mattastic — 2010-08-03T06:17:38-04:00 — #5
Thanks for your reply.
Can you help?
homepage = "<h2 class='draggable'>Bring n buy</h2><div class='container'>"
homepage += '<ul>'
homepage += "<li><a href='index.cfm?area=marketplace/index&page=view-forum&forumid=267'>Kingsize bed frame</a></li>"
Error: unterminated string literal
Source File: http://intranet/portal.cfm
Line: 24, Column: 16
homepage += "<li><a href='index.cfm?area=marketplace/index&page=view-forum&forumid=267'>
autisticcuckoo — 2010-08-04T01:09:23-04:00 — #6
</script> rather than in an external script file (
If so, the problem is most likely the closing tags you have in your strings.
In HTML (which includes pretend-XHTML) the
script element type has a content model of
CDATA, which behaves a bit oddly. One oddity is that the first occurrance of the character sequence '
</' followed by a name-start character will be interpreted as
</script> and thereby close the script tag.
To prevent this you need to escape that character sequence, which you can do by inserting a backslash character between the '<' and the '/'. That 'escapes' the '/' character.
homepage += "<li><a href='index.cfm?area=marketplace/index&page=view-forum&forumid=267'>Kingsize bed frame<\\/a><\\/li>"
Without the backslash characters in the end tags, the script tag is closed after 'bed frame' which means the string constant isn't properly terminated.