how to make javascript variable global?
| From: | Patricia Hu | Date: | Thu, 26 Oct 2000 23:00:46 +0000 |
| Subject: | how to make javascript variable global? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-22227@lists.php.net to get a copy of this message | ||
Hi PHP (and JavaScript) gurus,
I am trying to use JavaScript to get the execution time of a PHP script. Specifically: a gettime() function is defined in the HTML <HEAD> part, and to when the user clicks 'submit' button the then time in milisecond is assigned to variable start, and after the requested page is returned and loaded, JavaScript will get the current time in milisecond again, this time assigns it to variable finish, so I will be able to subtract the two to get the execution time.
My question is: it seems the var start can not be available for comparison when it is later called to compare with var finish. Is there anyway to make var start global?
Here are the relevant part of the code:
-----------------------------------------------------------------
/////////////////in <HTML><HEAD> part:
<script language='JavaScript'>
function gettime(){
var nowtime=new Date();
var milisec=nowtime.getTime();
return (milisec);
}
<script>
////////////////when clicking the SUBMIT button:
<script language='JavaScript'>
var start=gettime();</script>
<input type="submit" name="search" value="Start Search" onClick="alert(start);">///////////////when the page finishes loading: <script language='JavaScript'>
var finish=gettime();
document.write("start time is " + start);
document.write("finish time is " + finish);
document.write("exe time is"+ (finish-start) );
</script>
<input type=submit name=try value='exe time' onclick='alert(finish);'>
-------------------------------------------------------------------
Forgive me if you think this is not directly PHP. I am posting it here b/c the whole code is in PHP. Any help would be most appreciated.
Best regards,
Patricia
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Share information about yourself, create your own public profile at http://profiles.msn.com.