Page 1 of 1

a how-to question

Posted: Fri Apr 22, 2005 12:44 pm
by s.dot
I have two javascript functions. I would like for the second one to be dependant on the completion of the first one.

Here is the code.

Code: Select all

<script>
<!--
var timeout = 1000; var num = 0; var na = &quote;00&quote;; var secs = <? if($premiumarray&#1111;'premium'] == &quote;y&quote;){ echo &quote;10&quote;;} ELSE { echo &quote;20&quote;; } ?>;
function go(which){
	na = secs;
	if (secs < 10) { na = &quote;0&quote; + na; }
	document.getElementById(&quote;timerbox&quote;).innerHTML = &quote;<h3><font color=#FFFFFF>&quote; +na+ &quote;</font></h3>&quote;;
	secs = secs - 1
	if (secs+1 > 0) { setTimeout(&quote;go()&quote;,timeout); }
	if (secs+1 < 1) {	document.getElementById(&quote;timerbox&quote;).style.display='none'; showForm(which);	}
	}
function showForm(which) {
	showit = window.setTimeout(function() { which.style.display='block' }, '<? if($premiumarray&#1111;'premium'] == &quote;y&quote;){ echo &quote;10000&quote;;} ELSE { echo &quote;20000&quote;; } ?>');
	}
-->
</script>
And for the body tag I have this.

Code: Select all

<BODY onLoad=&quote;go(); showForm(document.getElementById('countDownText'));&quote;>
How can I make it so that the function showForm ONLY happens when var secs (from funtion Go() ) reaches 0 ?

As it is functioning now, if there is a heavily designed/programmed page, showForm will display before var secs = 0

Posted: Fri Apr 22, 2005 8:01 pm
by Chris Corbyn
Call the second funtion from inside the first function rather than onLoad in the <body> :wink:

Posted: Sat Apr 23, 2005 4:25 am
by s.dot
Very nice, I did that and it works good.

I'm not good with javascript so I didn't know how to remove the timeout from the second function, so I just set it to 0000. HA, whatever works. :P

Posted: Sat Apr 23, 2005 8:12 am
by Chris Corbyn

Code: Select all

function showForm(which) {
    which.style.display='block';
}