Sar1973
asked on
Cannot find the exact syntax of setTimeout with innerHTML as argument.
I am developing a very simple function that should allow me to display a countdown message:
var myTable=document.getElemen tById("myT able");
var myHTML0 = myTable.outerHTML;
var j=0;
var T=5;
for (g = 0; g<T; g++) {
j = T-g;
myMsg = "We have "+j+" seconds missing to go.";
myHTML = myHTML0.substring(0,myHTML 0.indexOf( "We")) +myMsg+myHTML0.substring(m yHTML0.ind exOf("We") +2,myHTML0 .length);
*** var k = setTimeout("document.getEl ementById( 'myNote'). innerHTML = myHTML", g*1000);
myHTML ="";
}
Unfortunately, I canno manage to spot the correct syntax of line ***. Can you suggest how? Thanx.
var myTable=document.getElemen
var myHTML0 = myTable.outerHTML;
var j=0;
var T=5;
for (g = 0; g<T; g++) {
j = T-g;
myMsg = "We have "+j+" seconds missing to go.";
myHTML = myHTML0.substring(0,myHTML
*** var k = setTimeout("document.getEl
myHTML ="";
}
Unfortunately, I canno manage to spot the correct syntax of line ***. Can you suggest how? Thanx.
ASKER
I have tried these:
1. (posted) setTimeout("document.getEl ementById( 'myNote'). innerHTML = myHTML", g*1000);
2. setTimeout("document.getEl ementById( 'myNote'). innerHTML = '" + myHTML + "'", g*1000);
3. setTimeout("document.getEl ementById( 'myNote'). innerHTML = "+ myHTML, g*1000);
4. setTimeout("document.getEl ementById( 'myNote'). innerHTML = \'myHTML\', g*1000); (or something similar).
In case 2. it says that I've inserted a string without termination, in the other cases the editor alerts of syntax errors (3.) or returns a null value (1.), so that the table gets empty; moreover it does not support jQuery.
1. (posted) setTimeout("document.getEl
2. setTimeout("document.getEl
3. setTimeout("document.getEl
4. setTimeout("document.getEl
In case 2. it says that I've inserted a string without termination, in the other cases the editor alerts of syntax errors (3.) or returns a null value (1.), so that the table gets empty; moreover it does not support jQuery.
ok great for case 2 :
setTimeout("document.getEl ementById( 'myNote'). innerHTML = '" + escape(myHTML) + "'", g*1000);
setTimeout("document.getEl
or :
setTimeout("document.getEl ementById( 'myNote'). innerHTML = '" + myHTML.replace(/'/g, "\\'") + "'", g*1000);
setTimeout("document.getEl
ASKER
Will test tomorrow and tell you, thanx in advance.
ASKER
"escape" does not work at all (gives unknow contents), while the other gives "string wothout termination" error as above.
please provide a direct link to see you page
ASKER
It's not published yet. But I'm not sure that I need to make the string portable with escape function; I should understand instead why I get "string without termination" error even if I point the HTML code with single marks.
about your "string without termination" error :
var blabla = "some string without error";
var bloblo = "string with-----> " <------- termination error";
var blabla = "some string without error";
var bloblo = "string with-----> " <------- termination error";
ASKER
Sorry, you are asking which is the exact error message I get?
No, I want you understand why you get the error.
bloblo have a double quote in the string, it need to be escaped
bloblo have a double quote in the string, it need to be escaped
ASKER
I can also tell you that without using quotes I get a blank content/value in the table in subject, while it works if I use the absolute syntax without timing "document.getElementById(' myNote').i nnerHTML = myHTML;".
You said : << "escape" does not work at all (gives unknow contents), >>
Could you post the content here
If you can publish this page I can help you more.
Could you post the content here
If you can publish this page I can help you more.
ASKER
Escape functions returns the HTML code replacing spaces and other characters with %20 or similar: it's not what I need. Probably the code I'm using encounters troubles durign the cycle (for ex. does not refresh the k variable in time) or misses some DIV, TD, BODY or other statement or discriminates between Ucase and Lcase.
I've read on w3schools tutorial that setTimeout variables must be named with different strings, that's why I was also asking how to combine eval syntax with setTimeout syntax.
As an alternative, I could think to insert a label or another object and give it a text value equal to the string I need to display.
I've read on w3schools tutorial that setTimeout variables must be named with different strings, that's why I was also asking how to combine eval syntax with setTimeout syntax.
As an alternative, I could think to insert a label or another object and give it a text value equal to the string I need to display.
>Escape functions returns the HTML code replacing spaces and other characters with %20 or similar: it's not what I need.
Could you post one generating the error?
Could you post one generating the error?
ASKER
Exactly (it's a literal translation): "Line 1, character 50, string constant without termination" or "Line 2, character 1, syntax error" in the 2 mentioned cases.
No, I want to see the string escaped :
blablabla%20blablabla
the full myHTML string escaped, I mean : escape(myHTML)
blablabla%20blablabla
%YX
blablablathe full myHTML string escaped, I mean : escape(myHTML)
blablabla%20blablabla%YXblablabla
ASKER
This is the original HTML:
<DIV style="WIDTH: 351px; HEIGHT: 25px" id=myNote align=left><TABLE style="DISPLAY: inline" border=0 cellSpacing=0 cellPadding=0 width=381>
<TBODY>
<TR>
<TD style="BORDER-BOTTOM: 1px solid; BORDER-LEFT: 1px solid; BORDER-TOP: 1px solid; BORDER-RIGHT: 1px solid" bgColor=#ff0000 width=383><FONT color=#ffffff face=Arial>Nota</FONT></TD ></TR></TB ODY></TABL E></DIV>
and this is the escaped HTML:
%0D%0A%3CDIV%20style%3D%22 WIDTH%3A%2 0351px%3B% 20HEIGHT%3 A%2025px%2 2%20id%3Dm yNote%20al ign%3Dleft %3E%3CTABL E%20style% 3D%22DISPL AY%3A%20in line%22%20 border%3D0 %20cellSpa cing%3D0%2 0cellPaddi ng%3D0%20w idth%3D381 %3E%0D%0A% 3CTBODY%3E %0D%0A%3CT R%3E%0D%0A %3CTD%20st yle%3D%22B ORDER-BOTT OM%3A%201p x%20solid% 3B%20BORDE R-LEFT%3A% 201px%20so lid%3B%20B ORDER-TOP% 3A%201px%2 0solid%3B% 20BORDER-R IGHT%3A%20 1px%20soli d%22%20bgC olor%3D%23 ff0000%20w idth%3D383 %3E%3CFONT %20color%3 D%23ffffff %20face%3D Arial%3ENo ta%3C/FONT %3E%3C/TD% 3E%3C/TR%3 E%3C/TBODY %3E%3C/TAB LE%3E%3C/D IV%3E
<DIV style="WIDTH: 351px; HEIGHT: 25px" id=myNote align=left><TABLE style="DISPLAY: inline" border=0 cellSpacing=0 cellPadding=0 width=381>
<TBODY>
<TR>
<TD style="BORDER-BOTTOM: 1px solid; BORDER-LEFT: 1px solid; BORDER-TOP: 1px solid; BORDER-RIGHT: 1px solid" bgColor=#ff0000 width=383><FONT color=#ffffff face=Arial>Nota</FONT></TD
and this is the escaped HTML:
%0D%0A%3CDIV%20style%3D%22
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It works! Good job; I know only have to fix a format trouble, since the new table appears padded left about 5 px from the original.
Open in new window
Additionaly check this : http://keith-wood.name/countdown.html