Re: [WSG] JavaScript and escaped quotes - THREAD CLOSED - EXPLANATION
My apologies for not explaining the thread closure earlier. I closed the thread due to the aggressive nature of the last post, not due to the topic of javascript. My concern was that the post could have lead to a possible flame war and this is definitely something we do not want to see on this list. The aim of the overall group and the list is to help others. This can only be achieved if we remain civil. Just so we are all clear: 1. EcmaScript (and Javascript) is a standard and a valid discussion point on this list - just as valid as any CSS discussions. 2. If you have a concern about a thread, please do not vent your wrath on the list. Instead, let Peter and I know. We may not respond immediately, but we will get back to you. If the thread is based on a topic you have no interest in, then there are many ways to deal with it locally, such as applying filters on incoming mail. Again, apologies for any confusion my thread closure may have caused. Russ >> This works. But what to do if the message also needs " inside? > > Can we keep the javascript cr*p off this list? Thanks! > ** The discussion list for http://webstandardsgroup.org/ See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help **
Re: [WSG] JavaScript and escaped quotes - THREAD CLOSED
** The discussion list for http://webstandardsgroup.org/ See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help **
Re: [WSG] JavaScript and escaped quotes
On 4/14/05 2:51 AM "Juergen Auer" <[EMAIL PROTECTED]> sent this out: >> var msg="Don't Look Now"; >> >> Don't Look Now > > This works. But what to do if the message also needs " inside? Can we keep the javascript cr*p off this list? Thanks! Rick Faaberg ** The discussion list for http://webstandardsgroup.org/ See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help **
Re: [WSG] JavaScript and escaped quotes
On 14 Apr 2005 at 15:35, Bruce Morrison wrote: > var msg="Don't Look Now"; > > Don't Look Now This works. But what to do if the message also needs " inside? Make it generic: var msg="Don" + String.fromCharCode(39) + " use " + String.fromCharCode(34) + "too" + String.fromCharCode(34) + " much ..." produces Don't use "too" much ... Best Regards Juergen Auer http://www.sql-und-xml.de/ ** The discussion list for http://webstandardsgroup.org/ See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help **
Re: [WSG] JavaScript and escaped quotes
var msg="Don't Look Now"; Don't Look Now Very smart Bruce. The other method's more compact, but that's some good lateral thinking. "Have You Validated Your Code?" John Horner(+612 / 02) 9333 3488 Senior Developer, ABC Online http://www.abc.net.au/ ** The discussion list for http://webstandardsgroup.org/ See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help **
Re: [WSG] JavaScript and escaped quotes
You have 3 options: 1. use ’ instead of ' 2. call you function as myfunction('Don\'t Look Now') 3. myfunction(unescape('Don%27t Look Now')) Thanks so much Dmitry, I've actually used a combination of the above. myfunction(escape('Don’t Look Now')) and then unescaped it at the "other end"... I can stop scratching my head now! "Have You Validated Your Code?" John Horner(+612 / 02) 9333 3488 Senior Developer, ABC Online http://www.abc.net.au/ ** The discussion list for http://webstandardsgroup.org/ See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help **
Re: [WSG] JavaScript and escaped quotes
On Thu, 2005-04-14 at 15:17, John Horner wrote: > Following up on my own post, but I neglected to say, the apostrophe > could be escaped, just for JavaScript purposes, like this: > > 'Don\'t Look Now' > > but this text is coming out of a CMS, and the same string needs to be > used both on the page and in the JavaScript. Set the text in a var then use that var in the onclick var msg="Don't Look Now"; Don't Look Now var msg="Don't Stop Now"; Don't Stop Now > > "Have You Validated Your Code?" > John Horner(+612 / 02) 9333 3488 > Senior Developer, ABC Online http://www.abc.net.au/ > > ** > The discussion list for http://webstandardsgroup.org/ > > See http://webstandardsgroup.org/mail/guidelines.cfm > for some hints on posting to the list & getting help > ** -- Bruce Morrison designIT http://www.designit.com.au ** The discussion list for http://webstandardsgroup.org/ See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help **
Re: [WSG] JavaScript and escaped quotes
> but this text is coming out of a CMS, and the same string needs to be > used both on the page and in the JavaScript. In this case put body of the function into inline script block - not a attribute value and use double quotes. Or another super hack is to put this text into hidden span under the A tag like Don't Look Nowlink text -- Best regards, Dmitry Baranovskiy ** The discussion list for http://webstandardsgroup.org/ See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help **
Re: [WSG] JavaScript and escaped quotes
Following up on my own post, but I neglected to say, the apostrophe could be escaped, just for JavaScript purposes, like this: 'Don\'t Look Now' but this text is coming out of a CMS, and the same string needs to be used both on the page and in the JavaScript. "Have You Validated Your Code?" John Horner(+612 / 02) 9333 3488 Senior Developer, ABC Online http://www.abc.net.au/ ** The discussion list for http://webstandardsgroup.org/ See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help **
Re: [WSG] JavaScript and escaped quotes
You have 3 options: 1. use ’ instead of ' 2. call you function as myfunction('Don\'t Look Now') 3. myfunction(unescape('Don%27t Look Now')) On 4/14/05, John Horner <[EMAIL PROTECTED]> wrote: > [Maybe a little off-topic but I thought you'd be likely to know] > > I have page titles which sometimes require single quotes, i.e. "Don't Look > Now" > > The titles also need to appear in a javascript onClick function like this: > > > > as you can guess, that breaks the JavaScript because of the quote in "Don't" > > so I escaped the quotes and now I have this: > > myfunction('Don't Look Now') > > but it still breaks in FireFox, and the JavaScript console comes up > with an error which points to the "'" as if it were a quote: > > Error: missing ) after argument list > myfunction('Don't Look Now') > ^ > > anyone got an explanation? Am I missing something obvious? It's the > same if I use ' instead. > > "Have You Validated Your Code?" > John Horner(+612 / 02) 9333 3488 > Senior Developer, ABC Online http://www.abc.net.au/ > > ** > The discussion list for http://webstandardsgroup.org/ > > See http://webstandardsgroup.org/mail/guidelines.cfm > for some hints on posting to the list & getting help > ** > > -- Best regards, Dmitry Baranovskiy ** The discussion list for http://webstandardsgroup.org/ See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help **
[WSG] JavaScript and escaped quotes
[Maybe a little off-topic but I thought you'd be likely to know] I have page titles which sometimes require single quotes, i.e. "Don't Look Now" The titles also need to appear in a javascript onClick function like this: as you can guess, that breaks the JavaScript because of the quote in "Don't" so I escaped the quotes and now I have this: myfunction('Don't Look Now') but it still breaks in FireFox, and the JavaScript console comes up with an error which points to the "'" as if it were a quote: Error: missing ) after argument list myfunction('Don't Look Now') ^ anyone got an explanation? Am I missing something obvious? It's the same if I use ' instead. "Have You Validated Your Code?" John Horner(+612 / 02) 9333 3488 Senior Developer, ABC Online http://www.abc.net.au/ ** The discussion list for http://webstandardsgroup.org/ See http://webstandardsgroup.org/mail/guidelines.cfm for some hints on posting to the list & getting help **