Click to See Complete Forum and Search --> : global variable


dsdsdsdsd
05-16-2004, 01:29 PM
hello;

I have dozens of functions running, several of which are using setTimeout(); a particular function1 gets called over and over again, and, as it turns out, this particular function1 triggers another function2 WHICH ONLY NEEDS TO BE TRIGGERED ONCE;

because the RETURN function kills its caller I cannot use a RETURN to send a how_many_times_has_function2_been_called variable to function2 from function1 which has a setTimeout() running;

ANSWER: I need a literal global variable; PHP makes this a very simple task;

any thoughts?

I hope my question is sensible

thanks
Shannon Burnett
Asheville NC USA

Khalid Ali
05-16-2004, 02:20 PM
hunm..did you try to use a global variable in javascript and if you have what errors did you get if any?

Pittimann
05-16-2004, 03:14 PM
Hi!

You could try something like this (replacing the alerts with code to be executed):<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var checkF2a=0;
var checkF2b=0;
function function1(){
//a bunch of code here
function2(checkF2b)
}
function function2(val){
//maybe some code???
if (checkF2a==val){
alert('ok');
}
if (checkF2a!=val){
alert('This function already ran!');
}
checkF2b++;
}
//-->
</script>
</head>
<body>
<a href="#" onclick="function1();return false;">click</a>
</body>
</html>Cheers - Pit

dsdsdsdsd
05-18-2004, 04:53 PM
pittimann and khalid ali, thanks for your responses;

pittimann, I have yet to try your solution but, yes, this will work; thanks;

Shannon Burnett
Asheville NC USA