61 users online (1 members and 60 guests)  


  Results 1 to 2 of 2

Related

  1. Replies: 2
  2. Variable in Form action field    Forum: Javascript Forum
    Replies: 4
  3. Form Action help    Forum: HTML Forum
    Replies: 1
  4. Trigger form action    Forum: HTML Forum
    Replies: 2
  5. Bizarre action of <TEXTAREA>    Forum: HTML Forum
    Replies: 3
  1. #1
    hzane's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2003
    Posts
    11

    delayed action using php + javascript.

    Here is my situation.

    User posts his form.
    One of the vars he posts is the time (in string format), another is avail (bool).....

    Ideally what should then occur is as soon the UPDATE query finishes a javascript counter function is called.

    Once the counter reaches zero a php function is called to update the DB clearing the row - and preparing the DB for the next entry (become available).

    My problem is how to stick the javascript and the php together???

    Another slightly less attractive solution would be, once the UPDATE query finishes, still w/ php an setInterval (or php substitute) is issued and the clear row function is called upon that php counters completion.

    To recap - I need to automattically update my database x number of minutes after an event. Ideally the countdown from event to x number of minutes would be displayed on the user's system....If that's not possible well, that's fine.

    I am really not sure where to start......
    Any thoughts, comments or ideas would be greatly appreciated and valued!

    much thanks.

  2. #2
    Rekcor's Avatar
    New User

    Status
    Offline
    Join Date
    Feb 2005
    Posts
    6
    Javascript will always start when PHP/MySQL is finished, because JS is client side while the PHP/MySQL are server side

    If I understand you right you should make something like this (im not a JS-expert, so the JS code I will write with my own words)

    Code:
    <?php
    if ($_POST['time'] and $_POST['avail']) //user has posted form
    {
      $sql="UPDATE blah";
      mysql_query($sql);
    }
    
    if ($_POST('countdownready'))
    {
      $sql="DELETE QUICK blah";
      mysql_query($sql);
    }
    ?>
    
    <script>
    Countdown code here
    if (Count==0)
    {
    document.getElementById('CountdownForm').submit();
    }
    </script>
    
    <form id="CountdownForm" action="<?php echo $PHP_SELF;?>">
    <input type="hidden" name="countdownready" value="1">
    </form>
    1. User posts form
    --> $_POST['time'] and $_POST['avail'] are given and

    Code:
    if ($_POST['time'] and $_POST['avail']) //user has posted form
    {
    (...)
    }
    will update MySQL-table

    2. User sees page
    --> on this page, a javascript countdown is busy counting down on the background. Once its finished, it posts a hidden form to the same page ($PHP_SELF)

    3. Second time the page loads.
    --> Javascript has posted form with a hidden field 'countdownready', so

    Code:
    if ($_POST('countdownready'))
    {
    (...)
    }
    deletes the row in the db

    I must say this is a strange and buggy way of doing things. The problems start when the user does not wait until the javascript countdown is finished....

    But I hope it helped!

    Regards,
    Koos



Tags for this Thread