a how-to question

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

a how-to question

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Call the second funtion from inside the first function rather than onLoad in the <body> :wink:
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

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