I can't seem to get either variable report1 or report2 to have a global scope, I know this problem seems really basic, but I just can't seem to find an answer.
I have to define the variable report1 when numClicks == 1, and then report2 when numClicks == 2. But JavaScript is forgetting the variables as soon as numClicks changes, which is understandable. However, I just cannot seem to widen the scope of the variables. I know for PHP you can do something like return $variable to make it global, but nothing is really working here in JavaScript.
<?
"<img height =\"16\" src = \"images/stapler.png\"
onclick=\"
numClicks++;
if(numClicks == 1){
var report1 = '".$reports[$i]."';
}
if(numClicks == 2){
var report2 = '".$reports[$i]."';
}
return confirm(report1);
\">\n";?>
When the script is executed, on the third click it is returning undefined.