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
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.
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"
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';
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'>
</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.