RE: [PHP] how to make javascript variable global?
| From: | Ozemail ) | Date: | Fri, 27 Oct 2000 01:07:27 +0000 |
| Subject: | RE: [PHP] how to make javascript variable global? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-22246@lists.php.net to get a copy of this message | ||
The problem is that you're not sending the "starttime" with your form. That is
why it doesn't know the starttime. Essenatially, when the user click on
the submit button it treats this as a new request even if you're submitting to the
same page. To accomplish what you want to do, it might be easier IMHO to do this:
1) Do nothing in the first page.
2) Once the submission is received on the 2nd page, at the start you start the counter ie get the
current time
3) Once your processing in the 2nd script is finished, you get the current time
4) subtract the finish time from the start and display,
either with jscript alert() or just a simple output to browser.
>
> 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.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>