Jump to content

Timer problem


jatter
 Share

Recommended Posts

I'm trying to make the timer like the example at http://www.w3schools.com/js/tryit.asp?file...timing_infinite.But I want to display the text just as normal text not in a box, does anyone knows how to do that?Edit: Forgot to add this, but I also want to redirect the user after a specific time. Should I use newLocation() for that?

Link to comment
Share on other sites

I'm trying to make the timer like the example at http://www.w3schools.com/js/tryit.asp?file...timing_infinite.But I want to display the text just as normal text not in a box, does anyone knows how to do that? [...]
That's just the border style of the text input control. You can set the css style of an html element like this:
<input style="border-style:none" type="text" id="txt">

or you can have a separate stylesheet to get your css styles organised better. See http://www.w3schools.com/css/default.asp for all the info on this.

[...]Edit: Forgot to add this, but I also want to redirect the user after a specific time. Should I use newLocation() for that?
To redirect to another page after the count reaches 5, for example:
if (c==5){  document.location.href="http://www.w3schools.com/"}

Link to comment
Share on other sites

Ok, thank you. It all makes sense now :) .The redirect script doesn't work or should I put it in the Head section?Edit: I put it in the head section, still no succes :).Edit2: Here's the code, I'm not sure if I'm allowed to bump or doublepost(couldn't find that in the guidelines) so I'll just do it in an edit.

<html><head><script type="text/javascript">var c=0var tfunction timedCount(){document.getElementById('txt').value=cc=c+1t=setTimeout("timedCount()",1000)}</script></head><body><script type="text/javascript"> if (c==5){    document.location="http://www.w3schools.com/"}</script><form><input type="button" value="Start training!" onClick="timedCount()"><input style="border-style:none" type="text" id="txt"></form><p>Click on the button above to start training.</p></body></html>

Link to comment
Share on other sites

You have put the test for the value of c into the body of the document, so it will get checked once, when the page loads. If you want it to be checked and do your redirection, then the test needs to be in the timedCount function. I'll leave it to you to work out if you want to put it before, or after you increment the value of c.Kevin

Link to comment
Share on other sites

Bump, I'm already waiting for 3 days.
Sorry, did not realise you had edited after the "all fine" post. Suggest you add a new post instead in future so folks are aware of the change (saw your notes wondering about that... if what I just said is wrong, the moderators can jump on it!) :) Anyway, what I meant was to put that stuff inside the existing timedCount function. This may not suit your eventual needs but it does work as a demo, which I think you wanted:
function timedCount(){document.getElementById('txt').value=cc=c+1if (c==5){  document.location.href="http://www.w3schools.com/"}t=setTimeout("timedCount()",1000)}

Link to comment
Share on other sites

You have put the test for the value of c into the body of the document, so it will get checked once, when the page loads. If you want it to be checked and do your redirection, then the test needs to be in the timedCount function. I'll leave it to you to work out if you want to put it before, or after you increment the value of c.Kevin
Thanks I now got it. I will try it as soon as I can.Edit: It worked! :) Thanks for the help!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...