SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to insert a php var into a form variable onsubmit?

    Hi All,

    I want to time how long it takes one of my form scripts to run _after_ I press the submit button.

    My php (to start the 'stopwatch' running) looks like this:
    <?
    $mt = explode(' ', microtime());
    $script_start_time = $mt[1] + $mt[0];
    ?>

    So I want to have an input field that looks like this:

    <input type='hidden' name='script_start_time' value='$script_start_time'>

    BUT $script_start_time must be populated at the exact moment the submit button is pressed, and not when the page where the form is first visited. Which is why I need a client side solution.

    Any takers?
    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    naturally, i'll always take a problem.

    Code:
    In the form tag:
    form onbeforeSubmit="sTime();"
    
    <script language="Javascript">
    
    function sTime(){
         d=new Date();
         document.form.field.value=d.getHour()+','+d.getMinute()+','+d.getSecond();
         }
    </script>
    Something like that.


    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm. I've got to compare two times - the time when the 'submit' button is clicked (the start time), and the time when the document is uploaded and the results page displayed (the end time).

    Now, the problem is that I have to use either
    1. The server time twice, OR
    2. The client (ie. local browser) time twice.

    If I use the javascript (client-side) time for the start and the php (server-side) time for the end, then the two will not be consistent.

    So it's a question of which to go with and how I implement it. There's no getting around the fact that I have to use a little javascript because I need to capture a time when the submit button is clicked. If it's possible I'd like to insert the server-side time into the javascript variable, but maybe that's a contradiction in terms :-)

    Still thinking...
    Web Design Perth Melbourne .:. Itomic Business Website Solutions
    Drupal Experts .:. Drupalise


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •