Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #33610 > unrolled thread
| Started by | justaguy <lichunshen84@gmail.com> |
|---|---|
| First post | 2017-07-22 20:56 -0700 |
| Last post | 2017-07-23 20:14 -0700 |
| Articles | 9 — 3 participants |
Back to article view | Back to comp.lang.javascript
Crazy Quotes! justaguy <lichunshen84@gmail.com> - 2017-07-22 20:56 -0700
Re: Crazy Quotes! "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-07-23 10:51 +0200
Re: Crazy Quotes! justaguy <lichunshen84@gmail.com> - 2017-07-23 06:17 -0700
Re: Crazy Quotes! "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-07-23 17:24 +0200
Re: Crazy Quotes! justaguy <lichunshen84@gmail.com> - 2017-07-23 08:36 -0700
Re: Crazy Quotes! Julio Di Egidio <julio@diegidio.name> - 2017-07-23 08:17 -0700
Re: Crazy Quotes! justaguy <lichunshen84@gmail.com> - 2017-07-23 08:33 -0700
Re: Crazy Quotes! Julio Di Egidio <julio@diegidio.name> - 2017-07-23 09:01 -0700
Re: Crazy Quotes! justaguy <lichunshen84@gmail.com> - 2017-07-23 20:14 -0700
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2017-07-22 20:56 -0700 |
| Subject | Crazy Quotes! |
| Message-ID | <bc8875a5-1a83-4bc4-8653-66d85ab67ec8@googlegroups.com> |
var cond = 'yes',
lineX = '',
oid = 7;
if (cond == 'Yes') {lineX =
"<br><input type=button value=Update onclick=doSomething("+oid+")>" +
" " +
"<a href=mycomment.cfm?Number="+oid+" target=_new>Comment</a>";
}
var doSomething = function(oid) {
console.log(oid);
}
Of the above, the quotes for the line with "onclick=soSomething()..." drives me nuts. How to fix them?
Thanks.
[toc] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2017-07-23 10:51 +0200 |
| Message-ID | <XnsA7BB6E617AF0Deejj99@194.109.6.166> |
| In reply to | #33610 |
justaguy <lichunshen84@gmail.com> wrote on 23 Jul 2017 in
comp.lang.javascript:
'use strict'; // add this for better debugging
> var cond = 'yes',
var cond = 'Yes'
// error[1]: case sensitive Yes
> lineX = '',
> oid = 7;
>
> if (cond == 'Yes') {lineX =
> "<br><input type=button value=Update onclick=doSomething("+oid+")>"
"<br><input type=button value=Update "
+ "onclick='doSomething("+oid+");'"
// error[2]: onclick needs [here single-]quoted content
> + " " +
> "<a href=mycomment.cfm?Number="+oid+" target=_new>Comment</a>";
> }
>
> var doSomething = function(oid) {
> console.log(oid);
>}
document.write(lineX);
// error[3]: you need the string to be inserted
>
> Of the above, the quotes for the line with "onclick=soSomething()..."
> drives me nuts. How to fix them?
You could easily have found this out by using the internal debugger
of your browser [I used Google-Chrome]:
<http://hannivoort.org/test/CrazyQuotes.jpg>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2017-07-23 06:17 -0700 |
| Message-ID | <d1444797-c377-4d0a-bdf3-8748ed80ebcb@googlegroups.com> |
| In reply to | #33612 |
On Sunday, July 23, 2017 at 4:51:12 AM UTC-4, Evertjan. wrote:
> wrote on 23 Jul 2017 in
> comp.lang.javascript:
>
> 'use strict'; // add this for better debugging
>
> > var cond = 'yes',
>
> var cond = 'Yes'
>
> // error[1]: case sensitive Yes
>
> > lineX = '',
> > oid = 7;
> >
> > if (cond == 'Yes') {lineX =
> > "<br><input type=button value=Update onclick=doSomething("+oid+")>"
>
> "<br><input type=button value=Update "
> + "onclick='doSomething("+oid+");'"
>
> // error[2]: onclick needs [here single-]quoted content
>
> > + " " +
> > "<a href=mycomment.cfm?Number="+oid+" target=_new>Comment</a>";
> > }
> >
> > var doSomething = function(oid) {
> > console.log(oid);
> >}
>
> document.write(lineX);
>
> // error[3]: you need the string to be inserted
>
> >
> > Of the above, the quotes for the line with "onclick=soSomething()..."
> > drives me nuts. How to fix them?
>
> You could easily have found this out by using the internal debugger
> of your browser [I used Google-Chrome]:
>
Thanks. But three things:
(1) The oid value needs to a string, ie, "NSS-892-A-233".
(2) Probably the ending ">" was missed in your
[ + "onclick='doSomething("+oid+");'" ] line
(3) For Chrome internal debugger, were you referring to dev tool's console tab?
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2017-07-23 17:24 +0200 |
| Message-ID | <XnsA7BBB11AFF04Eeejj99@194.109.6.166> |
| In reply to | #33613 |
justaguy <lichunshen84@gmail.com> wrote on 23 Jul 2017 in
comp.lang.javascript:
> On Sunday, July 23, 2017 at 4:51:12 AM UTC-4, Evertjan. wrote:
>> wrote on 23 Jul 2017 in
>> comp.lang.javascript:
>>
>> 'use strict'; // add this for better debugging
>>
>> > var cond = 'yes',
>>
>> var cond = 'Yes'
>>
>> // error[1]: case sensitive Yes
>>
>> > lineX = '',
>> > oid = 7;
>> >
>> > if (cond == 'Yes') {lineX =
>> > "<br><input type=button value=Update
>> > onclick=doSomething("+oid+")>"
>>
>> "<br><input type=button value=Update "
>> + "onclick='doSomething("+oid+");'"
>>
>> // error[2]: onclick needs [here single-]quoted content
>>
>> > + " " +
>> > "<a href=mycomment.cfm?Number="+oid+" target=_new>Comment</a>";
>> > }
>> >
>> > var doSomething = function(oid) {
>> > console.log(oid);
>> >}
>>
>> document.write(lineX);
>>
>> // error[3]: you need the string to be inserted
>>
>> >
>> > Of the above, the quotes for the line with "onclick=soSomething()..."
>> > drives me nuts. How to fix them?
>>
>> You could easily have found this out by using the internal debugger
>> of your browser [I used Google-Chrome]:
>>
>
> Thanks. But three things:
> (1) The oid value needs to a string, ie, "NSS-892-A-233".
You did specify a number value.
Is that reason to say "thanks, but" ???
>> > oid = 7;
var oid = '"NSS-892-A-233"';
> (2) Probably the ending ">" was missed in your
> [ + "onclick='doSomething("+oid+");'" ] line
You are unshure?
> (3) For Chrome internal debugger, were you referring to dev tool's
> console tab?
Why did you skip my link? The link gives the answer.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2017-07-23 08:36 -0700 |
| Message-ID | <c8798a9f-b087-4072-aef0-12ff14e96e54@googlegroups.com> |
| In reply to | #33615 |
On Sunday, July 23, 2017 at 11:24:47 AM UTC-4, Evertjan. wrote:
> justaguy wrote on 23 Jul 2017 in
> comp.lang.javascript:
>
> > On Sunday, July 23, 2017 at 4:51:12 AM UTC-4, Evertjan. wrote:
> >> wrote on 23 Jul 2017 in
> >> comp.lang.javascript:
> >>
> >> 'use strict'; // add this for better debugging
> >>
> >> > var cond = 'yes',
> >>
> >> var cond = 'Yes'
> >>
> >> // error[1]: case sensitive Yes
> >>
> >> > lineX = '',
> >> > oid = 7;
> >> >
> >> > if (cond == 'Yes') {lineX =
> >> > "<br><input type=button value=Update
> >> > onclick=doSomething("+oid+")>"
> >>
> >> "<br><input type=button value=Update "
> >> + "onclick='doSomething("+oid+");'"
> >>
> >> // error[2]: onclick needs [here single-]quoted content
> >>
> >> > + " " +
> >> > "<a href=mycomment.cfm?Number="+oid+" target=_new>Comment</a>";
> >> > }
> >> >
> >> > var doSomething = function(oid) {
> >> > console.log(oid);
> >> >}
> >>
> >> document.write(lineX);
> >>
> >> // error[3]: you need the string to be inserted
> >>
> >> >
> >> > Of the above, the quotes for the line with "onclick=soSomething()..."
> >> > drives me nuts. How to fix them?
> >>
> >> You could easily have found this out by using the internal debugger
> >> of your browser [I used Google-Chrome]:
> >>
> >
> > Thanks. But three things:
> > (1) The oid value needs to a string, ie, "NSS-892-A-233".
>
> You did specify a number value.
> Is that reason to say "thanks, but" ???
>
> >> > oid = 7;
>
> var oid = '"NSS-892-A-233"';
>
> > (2) Probably the ending ">" was missed in your
> > [ + "onclick='doSomething("+oid+");'" ] line
>
> You are unshure?
>
The most forgivable thing in the world is a typo type of omission !
> > (3) For Chrome internal debugger, were you referring to dev tool's
> > console tab?
>
> Why did you skip my link? The link gives the answer.
Sorry, I missed it. Thanks.
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2017-07-23 08:17 -0700 |
| Message-ID | <1a3f1888-e578-458c-9d0e-243efbb35ab9@googlegroups.com> |
| In reply to | #33610 |
On Sunday, July 23, 2017 at 5:57:09 AM UTC+2, justaguy wrote:
> var cond = 'yes',
> lineX = '',
> oid = 7;
>
> if (cond == 'Yes') {lineX =
> "<br><input type=button value=Update onclick=doSomething("+oid+")>" +
> " " +
> "<a href=mycomment.cfm?Number="+oid+" target=_new>Comment</a>";
> }
>
> var doSomething = function(oid) {
> console.log(oid);
> }
>
> Of the above, the quotes for the line with "onclick=soSomething()..."
> drives me nuts. How to fix them?
That code is just "ugly": the advice really is manipulate the DOM instead.
That said, it is not even just about escaping quotes within quotes: html
attributes should be html-encoded (no built-in function to do this, anyway
there are only 4 characters to escape: ", <, >, and &), plus url parameters
should be url-encoded (use encodeURIComponent there).
Anyway, assuming your attributes (your oid in particular) need no encoding,
here is how a single-quoted string looks like:
'<br><input type="button" value="Update" ' +
'onclick="doSomething("' + oid + '")">' +
' ' +
'<a href="mycomment.cfm?Number=' + oid + '" target="_new">Comment</a>'
And here is the double-quoted one, for comparison:
"<br><input type=\"button\" value=\"Update\" " +
"onclick=\"doSomething("" + oid + "")\">" +
" " +
"<a href=\"mycomment.cfm?Number=" + oid + "\" target=\"_new\">Comment</a>"
Not tested, there may be typos: but you get the picture...
HTH,
Julio
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2017-07-23 08:33 -0700 |
| Message-ID | <cb338d8c-34eb-4865-bcc5-634b64bc3613@googlegroups.com> |
| In reply to | #33614 |
On Sunday, July 23, 2017 at 11:18:04 AM UTC-4, Julio Di Egidio wrote:
> On Sunday, July 23, 2017 at 5:57:09 AM UTC+2, justaguy wrote:
> > var cond = 'yes',
> > lineX = '',
> > oid = 7;
> >
> > if (cond == 'Yes') {lineX =
> > "<br><input type=button value=Update onclick=doSomething("+oid+")>" +
> > " " +
> > "<a href=mycomment.cfm?Number="+oid+" target=_new>Comment</a>";
> > }
> >
> > var doSomething = function(oid) {
> > console.log(oid);
> > }
> >
> > Of the above, the quotes for the line with "onclick=soSomething()..."
> > drives me nuts. How to fix them?
>
> That code is just "ugly": the advice really is manipulate the DOM instead.
>
> That said, it is not even just about escaping quotes within quotes: html
> attributes should be html-encoded (no built-in function to do this, anyway
> there are only 4 characters to escape: ", <, >, and &), plus url parameters
> should be url-encoded (use encodeURIComponent there).
>
> Anyway, assuming your attributes (your oid in particular) need no encoding,
> here is how a single-quoted string looks like:
>
> '<br><input type="button" value="Update" ' +
> 'onclick="doSomething("' + oid + '")">' +
> ' ' +
> '<a href="mycomment.cfm?Number=' + oid + '" target="_new">Comment</a>'
>
> And here is the double-quoted one, for comparison:
>
> "<br><input type=\"button\" value=\"Update\" " +
> "onclick=\"doSomething("" + oid + "")\">" +
> " " +
> "<a href=\"mycomment.cfm?Number=" + oid + "\" target=\"_new\">Comment</a>"
>
> Not tested, there may be typos: but you get the picture...
Yes, it works. So, lesson learned: the key here is to use the
" in html format. Thought I tried to '" + oid + "' to no avail.
Thanks.
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2017-07-23 09:01 -0700 |
| Message-ID | <5de62444-a96d-466d-acd0-9710b1f2dcff@googlegroups.com> |
| In reply to | #33616 |
On Sunday, July 23, 2017 at 5:33:37 PM UTC+2, justaguy wrote:
> On Sunday, July 23, 2017 at 11:18:04 AM UTC-4, Julio Di Egidio wrote:
> > On Sunday, July 23, 2017 at 5:57:09 AM UTC+2, justaguy wrote:
> > > var cond = 'yes',
> > > lineX = '',
> > > oid = 7;
> > >
> > > if (cond == 'Yes') {lineX =
> > > "<br><input type=button value=Update onclick=doSomething("+oid+")>" +
> > > " " +
> > > "<a href=mycomment.cfm?Number="+oid+" target=_new>Comment</a>";
> > > }
> > >
> > > var doSomething = function(oid) {
> > > console.log(oid);
> > > }
> > >
> > > Of the above, the quotes for the line with "onclick=soSomething()..."
> > > drives me nuts. How to fix them?
> >
> > That code is just "ugly": the advice really is manipulate the DOM instead.
> >
> > That said, it is not even just about escaping quotes within quotes: html
> > attributes should be html-encoded (no built-in function to do this, anyway
> > there are only 4 characters to escape: ", <, >, and &), plus url parameters
> > should be url-encoded (use encodeURIComponent there).
> >
> > Anyway, assuming your attributes (your oid in particular) need no encoding,
> > here is how a single-quoted string looks like:
> >
> > '<br><input type="button" value="Update" ' +
> > 'onclick="doSomething("' + oid + '")">' +
> > ' ' +
> > '<a href="mycomment.cfm?Number=' + oid + '" target="_new">Comment</a>'
> >
> > And here is the double-quoted one, for comparison:
> >
> > "<br><input type=\"button\" value=\"Update\" " +
> > "onclick=\"doSomething("" + oid + "")\">" +
> > " " +
> > "<a href=\"mycomment.cfm?Number=" + oid + "\" target=\"_new\">Comment</a>"
> >
> > Not tested, there may be typos: but you get the picture...
>
> Yes, it works. So, lesson learned: the key here is to use the
> " in html format. Thought I tried to '" + oid + "' to no avail.
Or you could have used single-quotes there, since single-quotes need not be
html-encoded:
'onclick="doSomething(\'' + oid + '\')">' +
or:
"onclick=\"doSomething('" + oid + "')\">" +
Still a terrible approach... ;)
Julio
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2017-07-23 20:14 -0700 |
| Message-ID | <66fd59a7-e89c-4d40-be7c-1d80b0fa4c28@googlegroups.com> |
| In reply to | #33618 |
On Sunday, July 23, 2017 at 12:01:19 PM UTC-4, Julio Di Egidio wrote:
> On Sunday, July 23, 2017 at 5:33:37 PM UTC+2, justaguy wrote:
> > On Sunday, July 23, 2017 at 11:18:04 AM UTC-4, Julio Di Egidio wrote:
> > > On Sunday, July 23, 2017 at 5:57:09 AM UTC+2, justaguy wrote:
> > > > var cond = 'yes',
> > > > lineX = '',
> > > > oid = 7;
> > > >
> > > > if (cond == 'Yes') {lineX =
> > > > "<br><input type=button value=Update onclick=doSomething("+oid+")>" +
> > > > " " +
> > > > "<a href=mycomment.cfm?Number="+oid+" target=_new>Comment</a>";
> > > > }
> > > >
> > > > var doSomething = function(oid) {
> > > > console.log(oid);
> > > > }
> > > >
> > > > Of the above, the quotes for the line with "onclick=soSomething()..."
> > > > drives me nuts. How to fix them?
> > >
> > > That code is just "ugly": the advice really is manipulate the DOM instead.
> > >
> > > That said, it is not even just about escaping quotes within quotes: html
> > > attributes should be html-encoded (no built-in function to do this, anyway
> > > there are only 4 characters to escape: ", <, >, and &), plus url parameters
> > > should be url-encoded (use encodeURIComponent there).
> > >
> > > Anyway, assuming your attributes (your oid in particular) need no encoding,
> > > here is how a single-quoted string looks like:
> > >
> > > '<br><input type="button" value="Update" ' +
> > > 'onclick="doSomething("' + oid + '")">' +
> > > ' ' +
> > > '<a href="mycomment.cfm?Number=' + oid + '" target="_new">Comment</a>'
> > >
> > > And here is the double-quoted one, for comparison:
> > >
> > > "<br><input type=\"button\" value=\"Update\" " +
> > > "onclick=\"doSomething("" + oid + "")\">" +
> > > " " +
> > > "<a href=\"mycomment.cfm?Number=" + oid + "\" target=\"_new\">Comment</a>"
> > >
> > > Not tested, there may be typos: but you get the picture...
> >
> > Yes, it works. So, lesson learned: the key here is to use the
> > " in html format. Thought I tried to '" + oid + "' to no avail.
>
> Or you could have used single-quotes there, since single-quotes need not be
> html-encoded:
>
> 'onclick="doSomething(\'' + oid + '\')">' +
>
> or:
>
> "onclick=\"doSomething('" + oid + "')\">" +
>
> Still a terrible approach... ;)
>
> Julio
Ok, thanks.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web