473,229 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,229 software developers and data experts.

arcane quotes problem again

DL
The following line is dynamically generated, which works fine at least
with IE7 but what I want more out of it is to disable this button upon
click, so, pls see next line of my attempt to use CSS to disable its
display, however, nasty quote stumbled me.

var newStr = '... <div id='+i+'><button id="chk"+i name="chk"+i
onclick="doCheckbox(1,'+i2+','+nr2+');">Add another checkbox</button></
div>';
// as said, the above code works

var newStr ='... <div id='+i+'><button id="chk"+i name="chk"+i
onclick="document.getElementById('chk'+i).style.di splay=''none'';doCheckbox(1,'+i2+','+nr2+');">Add
another checkbox</button></div>';
// failed
// pls note, the quotes surrounding the word, none, are two single
quotes respectively, the idea is to escape single quote.

Do you have a solution?

Thanks.
Jun 27 '08 #1
8 1469
On May 26, 8:57 am, DL <tatata9...@gmail.comwrote:
The following line is dynamically generated, which works fine at least
with IE7 but what I want more out of it is to disable this button upon
click, so, pls see next line of my attempt to use CSS to disable its
display, however, nasty quote stumbled me.

var newStr = '... <div id='+i+'><button id="chk"+i name="chk"+i
onclick="doCheckbox(1,'+i2+','+nr2+');">Add another checkbox</button></
div>';
// as said, the above code works

var newStr ='... <div id='+i+'><button id="chk"+i name="chk"+i
onclick="document.getElementById('chk'+i).style.di splay=''none'';doCheckbox(1,'+i2+','+nr2+');">Add
another checkbox</button></div>';
// failed
// pls note, the quotes surrounding the word, none, are two single
quotes respectively, the idea is to escape single quote.

Do you have a solution?
You escape by backslash, just like in most other languages: \'

BTW, the string already breaks at: getElementById('chk <---- unescaped
single quote.
Jun 27 '08 #2
DL
On May 25, 9:23*pm, slebetman <slebet...@gmail.comwrote:
On May 26, 8:57 am, DL <tatata9...@gmail.comwrote:


The following line is dynamically generated, which works fine at least
with IE7 but what I want more out of it is to disable this button upon
click, so, pls see next line of my attempt to use CSS to disable its
display, however, nasty quote stumbled me.
var newStr = '... <div id='+i+'><button id="chk"+i name="chk"+i
onclick="doCheckbox(1,'+i2+','+nr2+');">Add another checkbox</button></
div>';
// as said, the above code works
var newStr ='... <div id='+i+'><button id="chk"+i name="chk"+i
onclick="document.getElementById('chk'+i).style.di splay=''none'';doCheckbox*(1,'+i2+','+nr2+');">Add
another checkbox</button></div>';
// failed
// pls note, the quotes surrounding the word, none, are two single
quotes respectively, the idea is to escape single quote.
Do you have a solution?

You escape by backslash, just like in most other languages: \'

BTW, the string already breaks at: getElementById('chk <---- unescaped
single quote.- Hide quoted text -

- Show quoted text -
Thanks and shame on me. Now I need a bit more help with quotes. The
following code use backslash to escape single quote within a singel
quoted long string, it generated an error, what's wrong?

var i = 1;
var newElement = document.createElement();
newElement.innerHTML ='Item\' +i+ \':&nbsp;\<input type="text" name=qCK
\'+i+\' size="60"\>&nbsp;\<br\&nbsp; <div id=\'+i+\'><button
id="chk"+i name="chk"+i onclick="document.getElementById(\'chk
\'+i).style.display=\'none\';doCheckbox(1,\'+i2+\' ,\'+nr2+\');">Add
another checkbox</button></div>';
Jun 27 '08 #3
"DL" <ta********@gmail.com wrote:
>
var i = 1;
var newElement = document.createElement();
newElement.innerHTML ='Item\' +i+ \':&nbsp;\<input type="text" name=qCK
\'+i+\' size="60"\>&nbsp;\<br\&nbsp; <div id=\'+i+\'><button
id="chk"+i name="chk"+i onclick="document.getElementById(\'chk
\'+i).style.display=\'none\';doCheckbox(1,\'+i2+\' ,\'+nr2+\');">Add
another checkbox</button></div>';

Yoa assign a string litteral to innerHTML. Taking away the enclosing quotes
and the escape characters, the contents of that string are (I insert
linebreaks and blanks for clarity - they are not part of the string value):
Item' +i+ ':
&nbsp;<input type="text" name=qCK'+i+' size="60">
&nbsp;<br>
&nbsp;
<div id='+i+'>
<button id="chk"+i name="chk"+i
onclick="document.getElementById('chk'+i).style.di splay='none';
doCheckbox(1,'+i2+','+nr2+');">
Add another checkbox
</button>
</div>

The problem is in the very first line: what is "Item'+i+':..." supposed to
mean?
Shouldn't that be "Item+i+':..." ?
Take away the escape \ in front of all quotes that should not appear in the
innerHTML (i.e. leave them only araound chk and none.)
I think it will then get the value
Item1:
&nbsp;<input type="text" name=qCK1 size="60">
&nbsp;<br>
&nbsp;
<div id=1>
<button id="chk"+i name="chk"+i
onclick="document.getElementById('chk'+i).style.di splay='none';
doCheckbox(1,value(i2),value(nr2));">
Add another checkbox
</button>
</div>

Which is still not what you want (it is not valid HTML).
I think it would be wiser to split things up:
var labeli = Item+i;
var inputName = 'qCK'+i;
var divID = i.toString();
var buttonID = 'chk'+i
.... innerHTML = labeli+'&nbsp;\<input type="text" name='+inputName+'
size="60"... etc.

Tom
Jun 27 '08 #4
DL
On May 26, 5:42*am, "Tom de Neef" <tden...@qolor.nlwrote:
"DL" <tatata9...@gmail.com*wrote:
var i = 1;
var newElement = document.createElement();
newElement.innerHTML ='Item\' +i+ \':&nbsp;\<input type="text" name=qCK

\'+i+\' size="60"\>&nbsp;\<br\&nbsp; <div id=\'+i+\'><button
id="chk"+i name="chk"+i *onclick="document.getElementById(\'chk
\'+i).style.display=\'none\';doCheckbox(1,\'+i2+\' ,\'+nr2+\');">Add
another checkbox</button></div>';

Yoa assign a string litteral to innerHTML. Taking away the enclosing quotes
and the escape characters, the contents of that string are (I insert
linebreaks and blanks for clarity - they are not part of the string value):
Item' +i+ ':
&nbsp;<input type="text" name=qCK'+i+' size="60">
&nbsp;<br>
&nbsp;
<div id='+i+'>
* <button id="chk"+i name="chk"+i
* * * *onclick="document.getElementById('chk'+i).style.d isplay='none';
doCheckbox(1,'+i2+','+nr2+');">
* * *Add another checkbox
* </button>
</div>

The problem is in the very first line: what is "Item'+i+':..." supposed to
mean?
Shouldn't that be "Item+i+':..." ?
Take away the escape \ in front of all quotes that should not appear in the
innerHTML (i.e. leave them only araound chk and none.)
I think it will then get the value
Item1:
&nbsp;<input type="text" name=qCK1 size="60">
&nbsp;<br>
&nbsp;
<div id=1>
* <button id="chk"+i name="chk"+i
* * * *onclick="document.getElementById('chk'+i).style.d isplay='none';
doCheckbox(1,value(i2),value(nr2));">
* * *Add another checkbox
* </button>
</div>

Which is still not what you want (it is not valid HTML).
I think it would be wiser to split things up:
var labeli = Item+i;
var inputName = 'qCK'+i;
var divID = i.toString();
var buttonID = 'chk'+i
... innerHTML = labeli+'&nbsp;\<input type="text" name='+inputName+'
size="60"... etc.

Tom
Thank you very much, Tom. I like your solution and approach, getting
very close...

var labeli = 'Checkbox item'+i;
var inputName = 'qCK'+i;
var divID = i.toString();
var buttonID = 'chk'+i

// alert(labeli+'&nbsp;\<input type="text" name='+inputName+'
size="60"\>&nbsp;\<br/>&nbsp;');
// ok

//alert('<div id='+divID+'><button id='+buttonID+' name='+buttonID+'
onclick="doCheckbox(1,'+i2+','+nr2+');">Add another checkbox</button></
div>');
// ok

// now put them together
// alert(labeli+'&nbsp;\<input type="text" name='+inputName+'
size="60"\>&nbsp;\<br/>&nbsp;<div id='+divID+'><button id='+buttonID+'
name='+buttonID+' onclick="doCheckbox(1,'+i2+','+nr2+');">Add another
checkbox</button></div>');
// ok

// final test
// alert(labeli+'&nbsp;\<input type="text" name='+inputName+'
size="60"\>&nbsp;\<br/>&nbsp;<div id='+divID+'><button id='+buttonID+'
name='+buttonID+' onclick="document.getElementById('+buttonID
+').style.display=\'none\';doCheckbox(1,'+i2+','+n r2+');">Add another
checkbox</button></div>');
// looks good
/* but the result of
document.getElementById('+buttonID+').style.displa y=\'none\';
is
document.getElementById(chk1).style.display='none' ;

Shouldn't it be
document.getElementById('chk1').style.display='non e';
I fumbled around a bit, couldn't get that output.
*/

newElement.innerHTML = labeli+'&nbsp;\<input type="text"
name='+inputName+' size="60"\>&nbsp;\<br/>&nbsp;<div id='+divID
+'><button id='+buttonID+' name='+buttonID+'
onclick="document.getElementById('+buttonID+').sty le.display=\'none
\';doCheckbox(1,'+i2+','+nr2+');">Add another checkbox</button></
div>';
Jun 27 '08 #5
/* but the result of
document.getElementById('+buttonID+').style.displa y=\'none\';
is
document.getElementById(chk1).style.display='none' ;
Shouldn't it be
document.getElementById('chk1').style.display='non e';
You're right.
You still have the double quotation marks to play with:
.... document.getElementById("'+buttonID+'").style.disp lay=\'none\';

Tom
Jun 27 '08 #6
DL
On May 27, 5:35*am, "Tom de Neef" <tden...@qolor.nlwrote:
/* but the result of
document.getElementById('+buttonID+').style.displa y=\'none\';
is
document.getElementById(chk1).style.display='none' ;
Shouldn't it be
document.getElementById('chk1').style.display='non e';

You're right.
You still have the double quotation marks to play with:
... *document.getElementById("'+buttonID+'").style.dis play=\'none\';

Tom
Thank you so much, it looks like javascripting does not like me :(
I tried both using
document.getElementById("'+buttonID+'").style.disp lay=\'none\';
inline as well as setting it to a var to no avail.

How come?

Jun 27 '08 #7
On May 27, 8:09 pm, DL <tatata9...@gmail.comwrote:
On May 27, 5:35 am, "Tom de Neef" <tden...@qolor.nlwrote:
/* but the result of
document.getElementById('+buttonID+').style.displa y=\'none\';
is
document.getElementById(chk1).style.display='none' ;
Shouldn't it be
document.getElementById('chk1').style.display='non e';
You're right.
You still have the double quotation marks to play with:
... document.getElementById("'+buttonID+'").style.disp lay=\'none\';
Tom

Thank you so much, it looks like javascripting does not like me :(
I tried both using
document.getElementById("'+buttonID+'").style.disp lay=\'none\';
inline as well as setting it to a var to no avail.

How come?
Ahh.. we're well into quoting hell here and you'll have the same
problem regardless what language you choose. This is one of the
reasons why inline HTML is often discouraged - quoting can get very
confusing very quickly. Instead do something like:

var i = 1;
var newElement = document.createElement();
newElement.innerHTML ='Item' + i + ':&nbsp;';
var newInput = document.createElement('input');
newInput.type = 'text';
newInput.name = 'qOK' + i;
newInput.size = 60;
newElement.appendChild(newInput);
newElement.appendChild(document.createElement('br' ));
var newDiv = document.createElement('div');
newDiv.id = i;
newElement.appendChild(newDiv);
var newButton = document.createElement('button');
newButton.id = 'chk' + i;
newButton.name = 'chk' + i;
newButton.onclick = function () {
document.getElementById('chk' + i).style.display = 'none';
doCheckbox(1,'i2', 'nr2');
}
newButton.innerHTML = 'Add another checkbox';
newDiv.appendChild(newButton);

of course you can use Thomas's appendFromJSON function to make this
much easier to type. See:
http://groups.google.com/group/comp....46b8fe9007c8e0
Jun 27 '08 #8
DL
>
Thank you so much, it looks like javascripting does not like me :(
I tried both using
document.getElementById("'+buttonID+'").style.disp lay=\'none\';
inline as well as setting it to a var to no avail.
How come?

Ahh.. we're well into quoting hell here and you'll have the same
problem regardless what language you choose. This is one of the
reasons why inline HTML is often discouraged - quoting can get very
confusing very quickly. Instead do something like:

var i = 1;
var newElement = document.createElement();
newElement.innerHTML ='Item' + i + ':&nbsp;';
var newInput = document.createElement('input');
newInput.type = 'text';
newInput.name = 'qOK' + i;
newInput.size = 60;
newElement.appendChild(newInput);
newElement.appendChild(document.createElement('br' ));
var newDiv = document.createElement('div');
newDiv.id = i;
newElement.appendChild(newDiv);
var newButton = document.createElement('button');
newButton.id = 'chk' + i;
newButton.name = 'chk' + i;
newButton.onclick = function () {
* document.getElementById('chk' + i).style.display = 'none';
* doCheckbox(1,'i2', 'nr2');}

newButton.innerHTML = 'Add another checkbox';
newDiv.appendChild(newButton);

of course you can use Thomas's appendFromJSON function to make this
much easier to type. See:http://groups.google.com/group/comp....frm/thread...- Hide quoted text -

- Show quoted text -
Tom, I'm out of the hell now, at least for now :) you taught me how
to escape the single quote, however, I did not fully utilize it in
this situation and when I revisited it again just now I resolved it
(man, I hate javascripting, so messay. But I expect there would be
more advanced javascript headaches ahead...
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: beliavsky | last post by:
The code for text in open("file.txt","r"): print text.replace("foo","bar") replaces 'foo' with 'bar' in a file, but how do I avoid changing text inside single or double quotes? For making...
2
by: August | last post by:
In my continuing attempt to make a user module for my CMS work, I keep running into errors with the folowing query, which makes no sense to me at all: INSERT IGNORE INTO...
17
by: bearophileHUGS | last post by:
Hello, I know this topic was discussed a *lot* in the past, sorry if it bores you... >From the Daily Python-URL I've seen this interesting Floating Point Benchmark:...
3
by: Stefania Scott | last post by:
How do I resolve the problem of passing a string that has quotes within in a SQL statement? Sometimes the string contains a single quote (') and some others it contains the double quote (")? Any...
6
by: G. | last post by:
This is an obvious bug in the String.Replace function: //load a XML string into a document XmlDocument doc = new XmlDocument(); doc.LoadXml("<test id='' />"); //Obtain the string...
16
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array...
4
by: vighnesh | last post by:
Hello EveryOne In my project I have to parse a string in Quotes as without Quotes.I tried the following code but it didn't work to me. I again getting the string with Quotes, Can Anybody suggest...
4
by: Justin Fancy | last post by:
Hi everyone, I need to replace all instances of a double quote(") with two single quotes('') in a text file. I already have some replacements of strings going on, but I tried this one, but the...
6
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello, I have some XML that is returned to my application from another vendor that I cannot change before it gets to me. I can only alter it after it gets to my application. That being said, I...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.