Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #12306

Re: Transposing single and double quotes.

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Newsgroups comp.lang.javascript
Subject Re: Transposing single and double quotes.
Date Wed, 29 Feb 2012 20:47:43 +0200
Organization A noiseless patient Spider
Lines 33
Message-ID <jilrsd$6hv$1@dont-email.me> (permalink)
References <u8fsk7h2shahn6niukmv2mb89ekmllhtbe@4ax.com> <h3rsk7peqfvchuii4vnit5vd30ecjmnbo7@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Wed, 29 Feb 2012 18:47:41 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="ngroV0xYIIv0dzjhyZhv5A"; logging-data="6719"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UZ+yiokQaMQ+Iim+TjzIv"
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2
In-Reply-To <h3rsk7peqfvchuii4vnit5vd30ecjmnbo7@4ax.com>
X-Antivirus-Status Clean
X-Antivirus avast! (VPS 120229-0, 29.02.2012), Outbound message
Cancel-Lock sha1:p8CxBlLCW6ZclUPyNVnvLyV77iQ=
Xref x330-a1.tempe.blueboxinc.net comp.lang.javascript:12306

Show key headers only | View raw


2012-02-29 20:27, Swifty wrote:

> How, in HTML, would I enter
> the JavaScript necessary to get an alert popup:
>
> Please don't click the "Click" button again.
>
> Now, no matter what I choose as the opening quote, I'll run into a
> premature matching character in my text.

That would happen if the string is part of an (event) attribute. In that 
case, if you need to include both the Ascii apostrophe (') and the Ascii 
quotation mark in the same attribute value, then you need to use HTML 
escape for either of them, e.g.

title='Please don&#39;t click the "Click" button again'

If the string needs to appear between quotation marks in JavaScript 
code, like alert('...'), then things get even more inconvenient.

But you normally avoid these issues by placing JavaScript code in 
<script> elements, or better still in external files. Even if the event 
handler is simple, it may pay off to write it as a function, say

function alarm() {
   alert('Please don\'t click the "Click" button again');
}

and then the event attribute is simple, e.g. onclick="alarm()".


-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Transposing single and double quotes. Swifty <steve.j.swift@gmail.com> - 2012-02-29 15:04 +0000
  Re: Transposing single and double quotes. "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-02-29 17:27 +0200
    Re: Transposing single and double quotes. Swifty <steve.j.swift@gmail.com> - 2012-02-29 18:17 +0000
  Re: Transposing single and double quotes. Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-29 07:28 -0800
  Re: Transposing single and double quotes. Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-02-29 16:39 +0100
  Re: Transposing single and double quotes. Swifty <steve.j.swift@gmail.com> - 2012-02-29 18:27 +0000
    Re: Transposing single and double quotes. Swifty <steve.j.swift@gmail.com> - 2012-02-29 18:38 +0000
    Re: Transposing single and double quotes. KR <kristian.rasmussen@broadpark.no.spam.com> - 2012-02-29 19:45 +0100
      Re: Transposing single and double quotes. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-29 19:59 +0100
        Re: Transposing single and double quotes. "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-29 22:28 +0000
          Re: Transposing single and double quotes. "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-03-01 07:52 +0200
            Re: Transposing single and double quotes. "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-01 07:54 +0000
              Re: Transposing single and double quotes. "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-03-01 10:18 +0200
                Re: Transposing single and double quotes. "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-01 15:21 +0000
                Re: Transposing single and double quotes. "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-03-01 18:07 +0200
              Re: Transposing single and double quotes. Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-03-01 10:30 +0100
                Re: Transposing single and double quotes. "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-01 15:29 +0000
                Re: Transposing single and double quotes. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-03-01 22:10 +0100
                Re: Transposing single and double quotes. Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-03-02 11:02 +0100
                Re: Transposing single and double quotes. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-03-02 13:17 +0100
                Re: Transposing single and double quotes. Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-03-05 10:09 +0100
                Re: Transposing single and double quotes. John G Harris <john@nospam.demon.co.uk> - 2012-03-02 16:27 +0000
              Re: Transposing single and double quotes. Dr J R Stockton <reply1209@merlyn.demon.co.uk> - 2012-03-02 22:05 +0000
                Re: Transposing single and double quotes. "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-03 08:35 +0000
    Re: Transposing single and double quotes. "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-02-29 20:47 +0200
      Re: Transposing single and double quotes. Swifty <steve.j.swift@gmail.com> - 2012-03-01 07:19 +0000
    Re: Transposing single and double quotes. Gene Wirchenko <genew@ocis.net> - 2012-02-29 14:18 -0800
  Re: Transposing single and double quotes. Dr J R Stockton <reply1209@merlyn.demon.co.uk> - 2012-03-01 21:55 +0000

csiph-web