i am searching some script that counting seconds...
for example
1..2..3..4..5..6..7..8..9..10!
stopes after 10 and do nothing....
has someone cross over script like this?
i am searching some script that counting seconds...
for example
1..2..3..4..5..6..7..8..9..10!
stopes after 10 and do nothing....
has someone cross over script like this?
Erm...Code:<script type="text/javascript"> function count(el, start, stop) { el = el.firstChild || el.appendChild(document.createTextNode("")); start = start || 0; stop = stop || 10; var c = start, inc = function() { if (c > stop) { clearInterval(t); el = null; } else el.nodeValue = c++; }, t = setInterval(inc, 1000); } </script> </head> <body> <p onclick="count(this);">Click here to begin counting.</p>
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
i already have a script:
i need to add this counting function inside of this script in order that when the timeout will shoot, that the seconds will strat running.Code:<body onLoad="setTimeout('check_Redirect()', 30000);"> <script type="text/javascript"> function check_Redirect(){ document.getElementById("alertmsg").innerHTML = "<p style='background:#000000;color:#ffffff;'>You have 10 seconds left!"</p>; } <div id="alertmsg" name="alertmsg"></div> </script>
i tried to fit this script to my script but it not working...just doing nothing...can you show me how to combine them ?
Code:<style type="text/css"> .timer { color: white; background-color: black; } </style> <script type="text/javascript"> function count(el, start, stop) { el = el.firstChild || el.appendChild(document.createTextNode("")); start = start || 0; stop = stop || 10; var c = start, inc = function() { if (c > stop) { clearInterval(t); el = null; } else el.nodeValue = c++; }, t = setInterval(inc, 1000); } onload = function() { setTimeout(function() { count(document.getElementById("timer")); }, 30000); }; </script> </head> <body> <p class="timer">You have <span id="timer">plenty of time</span> left.</p>
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
twey, i need to use
and the counting function got to be part of this scriptCode:<body onLoad="setTimeout('check_Redirect()', 30000);">
how can i do this?
please look at my script and tell me where i got wrong...
if i call the script like this;Code:<body onLoad="setTimeout('if(c==null) c=setInterval('startClock()',1000);', 50000);"> <script type="text/javascript"> var c=null; var ctr=10; function startClock(theLink){ var o=document.getElementById('sec'); var s=ctr<10?" second":" seconds"; o.innerHTML="<p style='background:#000000;color:#ffffff;'>You have "+(ctr) +s +" left</p>"; ctr--; if(ctr<0){clearInterval(c); return false;} } </script> </head> <body> <div id="sec"></div>
<input type="button" value="Start" onClick="if(c==null) c=setInterval('startClock()',1000);">
it is working
but i need it to be called from the timeout as i tried above...
The snippet of code you provided uses a couple of bad practices, namely inline event handlers and passing strings to setTimeout(). Additionally, camel-casing "onload" breaks compatibility with XHTML for no reason. I suggest dropping it in favour of my script-assigned event handler. Your attempt also uses inline style and innerHTML, again signs of bad coding: inline style causes unnecessary duplication and mitigates a lot of the benefits of using CSS in the first place, and innerHTML is non-standard and will not work in XHTML pages, unnecessarily reducing reliability and portability.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
then how we use your code inside the check_Redirect()
that will be called with
?Code:<body onLoad="setTimeout('check_Redirect()', 30000);">
Don't call it like that. It's bad. It does the equivalent already here:Code:onload = function() { setTimeout(function() { count(document.getElementById("timer")); }, 30000); };
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
i am using "div"Code:<script type="text/javascript"> function count(el, start, stop) { el = el.firstChild || el.appendChild(document.createTextNode("")); start = start || 10; stop = stop || 0; var c = start, inc = function() { if (c < stop) { clearInterval(t); el = null; } else el.nodeValue = c--; }, t = setInterval(inc, 1000); } onload = function() { setTimeout(function() { count(document.getElementById("timer")); }, 10000); }; </script> </head> <body> <div id="timer"></div>
i want that it will apear on screen only when the timeout over...
+i want that there will be a black background=#000000 and white font #ffffff
how i can add those things?
if this script can be run from <body onLoad="setTimeout('????()', 30000);">
i will be happy to know how![]()
Last edited by hantz; 11-12-2007 at 10:04 AM.
Bookmarks