473,799 Members | 3,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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+'><butto n id="chk"+i name="chk"+i
onclick="doChec kbox(1,'+i2+',' +nr2+');">Add another checkbox</button></
div>';
// as said, the above code works

var newStr ='... <div id='+i+'><butto n id="chk"+i name="chk"+i
onclick="docume nt.getElementBy Id('chk'+i).sty le.display=''no ne'';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 1490
On May 26, 8:57 am, DL <tatata9...@gma il.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+'><butto n id="chk"+i name="chk"+i
onclick="doChec kbox(1,'+i2+',' +nr2+');">Add another checkbox</button></
div>';
// as said, the above code works

var newStr ='... <div id='+i+'><butto n id="chk"+i name="chk"+i
onclick="docume nt.getElementBy Id('chk'+i).sty le.display=''no ne'';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...@gmai l.comwrote:
On May 26, 8:57 am, DL <tatata9...@gma il.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+'><butto n id="chk"+i name="chk"+i
onclick="doChec kbox(1,'+i2+',' +nr2+');">Add another checkbox</button></
div>';
// as said, the above code works
var newStr ='... <div id='+i+'><butto n id="chk"+i name="chk"+i
onclick="docume nt.getElementBy Id('chk'+i).sty le.display=''no ne'';doCheckbox *(1,'+i2+','+nr 2+');">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.create Element();
newElement.inne rHTML ='Item\' +i+ \':&nbsp;\<inpu t type="text" name=qCK
\'+i+\' size="60"\>&nbs p;\<br\&nbsp; <div id=\'+i+\'><but ton
id="chk"+i name="chk"+i onclick="docume nt.getElementBy Id(\'chk
\'+i).style.dis play=\'none\';d oCheckbox(1,\'+ i2+\',\'+nr2+\' );">Add
another checkbox</button></div>';
Jun 27 '08 #3
"DL" <ta********@gma il.com wrote:
>
var i = 1;
var newElement = document.create Element();
newElement.inne rHTML ='Item\' +i+ \':&nbsp;\<inpu t type="text" name=qCK
\'+i+\' size="60"\>&nbs p;\<br\&nbsp; <div id=\'+i+\'><but ton
id="chk"+i name="chk"+i onclick="docume nt.getElementBy Id(\'chk
\'+i).style.dis play=\'none\';d oCheckbox(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="docume nt.getElementBy Id('chk'+i).sty le.display='non e';
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="docume nt.getElementBy Id('chk'+i).sty le.display='non e';
doCheckbox(1,va lue(i2),value(n r2));">
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='+inputNam e+'
size="60"... etc.

Tom
Jun 27 '08 #4
DL
On May 26, 5:42*am, "Tom de Neef" <tden...@qolor. nlwrote:
"DL" <tatata9...@gma il.com*wrote:
var i = 1;
var newElement = document.create Element();
newElement.inne rHTML ='Item\' +i+ \':&nbsp;\<inpu t type="text" name=qCK

\'+i+\' size="60"\>&nbs p;\<br\&nbsp; <div id=\'+i+\'><but ton
id="chk"+i name="chk"+i *onclick="docum ent.getElementB yId(\'chk
\'+i).style.dis play=\'none\';d oCheckbox(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="docum ent.getElementB yId('chk'+i).st yle.display='no ne';
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="docum ent.getElementB yId('chk'+i).st yle.display='no ne';
doCheckbox(1,va lue(i2),value(n r2));">
* * *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='+inputNam e+'
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='+inputNam e+'
size="60"\>&nbs p;\<br/>&nbsp;');
// ok

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

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

// final test
// alert(labeli+'& nbsp;\<input type="text" name='+inputNam e+'
size="60"\>&nbs p;\<br/>&nbsp;<div id='+divID+'><b utton id='+buttonID+'
name='+buttonID +' onclick="docume nt.getElementBy Id('+buttonID
+').style.displ ay=\'none\';doC heckbox(1,'+i2+ ','+nr2+');">Ad d another
checkbox</button></div>');
// looks good
/* but the result of
document.getEle mentById('+butt onID+').style.d isplay=\'none\' ;
is
document.getEle mentById(chk1). style.display=' none';

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

newElement.inne rHTML = labeli+'&nbsp;\ <input type="text"
name='+inputNam e+' size="60"\>&nbs p;\<br/>&nbsp;<div id='+divID
+'><button id='+buttonID+' name='+buttonID +'
onclick="docume nt.getElementBy Id('+buttonID+' ).style.display =\'none
\';doCheckbox(1 ,'+i2+','+nr2+' );">Add another checkbox</button></
div>';
Jun 27 '08 #5
/* but the result of
document.getEle mentById('+butt onID+').style.d isplay=\'none\' ;
is
document.getEle mentById(chk1). style.display=' none';
Shouldn't it be
document.getEle mentById('chk1' ).style.display ='none';
You're right.
You still have the double quotation marks to play with:
.... document.getEle mentById("'+but tonID+'").style .display=\'none \';

Tom
Jun 27 '08 #6
DL
On May 27, 5:35*am, "Tom de Neef" <tden...@qolor. nlwrote:
/* but the result of
document.getEle mentById('+butt onID+').style.d isplay=\'none\' ;
is
document.getEle mentById(chk1). style.display=' none';
Shouldn't it be
document.getEle mentById('chk1' ).style.display ='none';

You're right.
You still have the double quotation marks to play with:
... *document.getEl ementById("'+bu ttonID+'").styl e.display=\'non e\';

Tom
Thank you so much, it looks like javascripting does not like me :(
I tried both using
document.getEle mentById("'+but tonID+'").style .display=\'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...@gma il.comwrote:
On May 27, 5:35 am, "Tom de Neef" <tden...@qolor. nlwrote:
/* but the result of
document.getEle mentById('+butt onID+').style.d isplay=\'none\' ;
is
document.getEle mentById(chk1). style.display=' none';
Shouldn't it be
document.getEle mentById('chk1' ).style.display ='none';
You're right.
You still have the double quotation marks to play with:
... document.getEle mentById("'+but tonID+'").style .display=\'none \';
Tom

Thank you so much, it looks like javascripting does not like me :(
I tried both using
document.getEle mentById("'+but tonID+'").style .display=\'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.create Element();
newElement.inne rHTML ='Item' + i + ':&nbsp;';
var newInput = document.create Element('input' );
newInput.type = 'text';
newInput.name = 'qOK' + i;
newInput.size = 60;
newElement.appe ndChild(newInpu t);
newElement.appe ndChild(documen t.createElement ('br'));
var newDiv = document.create Element('div');
newDiv.id = i;
newElement.appe ndChild(newDiv) ;
var newButton = document.create Element('button ');
newButton.id = 'chk' + i;
newButton.name = 'chk' + i;
newButton.oncli ck = function () {
document.getEle mentById('chk' + i).style.displa y = 'none';
doCheckbox(1,'i 2', 'nr2');
}
newButton.inner HTML = 'Add another checkbox';
newDiv.appendCh ild(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.getEle mentById("'+but tonID+'").style .display=\'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.create Element();
newElement.inne rHTML ='Item' + i + ':&nbsp;';
var newInput = document.create Element('input' );
newInput.type = 'text';
newInput.name = 'qOK' + i;
newInput.size = 60;
newElement.appe ndChild(newInpu t);
newElement.appe ndChild(documen t.createElement ('br'));
var newDiv = document.create Element('div');
newDiv.id = i;
newElement.appe ndChild(newDiv) ;
var newButton = document.create Element('button ');
newButton.id = 'chk' + i;
newButton.name = 'chk' + i;
newButton.oncli ck = function () {
* document.getEle mentById('chk' + i).style.displa y = 'none';
* doCheckbox(1,'i 2', 'nr2');}

newButton.inner HTML = 'Add another checkbox';
newDiv.appendCh ild(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
3680
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 changes to Python code, I would also like to avoid changing text in comments, either the '#' or '""" ... """' kind.
2
1532
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 mos_comprofiler(id,user_id) SELECT id,id FROM mos_users"; where mos_comprofiler is a new parallel User DB and mos_users is the original database of users. This first query is supposed to work when there is a id column in mos_users. However, my mos_users table has a...
17
2206
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: http://www.fourmilab.ch/fourmilog/archives/2005-08/000567.html This is the source pack: http://www.fourmilab.ch/fbench/fbench.zip
3
3172
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 clue... Thank you, Stefania
6
22214
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 again...Converts my '' to ""...strange, but ok. String strXML = doc.OuterXml; //trying to convert back the single quotes to double quotes
16
5888
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 with the following elements arr(0) = "MyString" arr(1) = 40 arr(2) = "Hello world"
4
2493
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 me where I went wrong? Thanks in advance. code:
4
7477
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 syntax is being read wrong. Here is the code: lineFile1 = sr.ReadLine
6
3098
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 am having a problem loading the XML correctly into my app. Here is the code: ==================================== Dim sPaymentXML as String
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10231
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9073
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.