Page 1 of 1

if/else number of seconds

Posted: Sat Mar 19, 2005 5:54 pm
by s.dot
I have a javascript that looks like this

Code: Select all

<HTML>
<HEAD>
<TITLE>title here</TITLE>
<script>
<!--
var timeout = 1000; var num = 0; var na = &quote;00&quote;; var secs = 20;

function go(){ na = secs; if (secs < 10) { na= &quote;0&quote; + na; }
document.getElementById(&quote;countDownText&quote;).innerHTML = na;

secs = secs - 1

if (secs+1 < 1) {
document.getElementById(&quote;countDownText&quote;).innerHTML = &quote;Go&quote;;}
if (secs+1 > 0) { setTimeout(&quote;go();&quote;,timeout); }
}
-->
</script>
&#1111;/head]
then to make the function work my HTML looks like this

Code: Select all

<BODY onLoad=&quote;go();&quote;BGCOLOR=&quote;#666666&quote; LEFTMARGIN=&quote;0&quote; TOPMARGIN=&quote;0&quote;>
<div id=&quote;countDownText&quote;></div>
This displays a countdown from 20 to 0. What I would like to do is after the time is up, display a link to the next page. Which I can do fine. But I'd like to do a check to see if seconds > 0 = "You're moving to fast" ELSE process next page

I don't know how to store the number of seconds in a variable to do this?

Posted: Sat Mar 19, 2005 6:09 pm
by John Cartwright
Wrong Forum

Moved to client side.

Posted: Sat Mar 19, 2005 8:50 pm
by feyd
you can either use a cookie, or generate a form that can post a one-time key to the other page, I guess..

I don't really see the point, but that's your problem, not mine ;)

Posted: Sun Mar 20, 2005 12:38 am
by s.dot
can I turn the number of seconds into a variable that would be put inside of a <ipput type="hidden"> tag, to use when the form is submitted?

Posted: Sun Mar 20, 2005 8:52 am
by feyd
that's easily faked... but yes. You already have it in a variable.. we've talked about setting form fields dynamically a lot in this section..

...

Posted: Mon Mar 21, 2005 4:51 am
by Calimero
add - onClick event on the link - when user clicks on it trigger a function that checks if the number of seconds is 0 or more and do the action you wish.

Just to add - have you tested if your time-out "gate" can go in -1, -2, -3 - because you use it for security reasons just work a little on it - although it should work as is.

hope this helps.
See ya.

Posted: Wed Mar 23, 2005 9:55 am
by s.dot

Code: Select all

<script>
<!--
var timeout = 1000; var num = 0; var na = &quote;00&quote;; var secs = 20;

function go(){ na = secs; if (secs < 10) { na= &quote;0&quote; + na; }
document.getElementById(&quote;countDownText&quote;).innerHTML = na;

secs = secs - 1

if (secs+1 < 1) {
document.getElementById(&quote;countDownText&quote;).innerHTML = &quote;<a href=\&quote;surf_frame.php?surfed=yes&numsecs=secs+1\&quote;><h3>Go</h3></a>&quote;;}
if (secs+1 > 0) { setTimeout(&quote;go();&quote;,timeout); }
}
-->
</script>
how can I change the link <a href=\"surf_frame.php?surfed=yes&numsecs=secs+1\"> into a link where secs+1 will be the variable for the number of seconds? instead of it writing secs+1 into the link?

Posted: Wed Mar 23, 2005 9:57 am
by feyd
break out of the string for that part.

Posted: Wed Mar 23, 2005 10:13 am
by s.dot
yes, I'm not aware of how to do that in javascript

Posted: Wed Mar 23, 2005 10:22 am
by feyd

Code: Select all

document.getElementById(&quote;countDownText&quote;).innerHTML = '&lt;a href=&quote;surf_frame.php?surfed=yes&amp;numsecs=' + (secs+1) + '&quote;&gt;&lt;h3&gt;Go&lt;/h3&gt;&lt;/a&gt;';}

Posted: Wed Mar 23, 2005 10:25 am
by s.dot
feyd, I love you.

In a nonsexual way
ahaha