SitePoint Sponsor

User Tag List

Results 1 to 1 of 1

Thread: 30 minute timer

  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2004
    0 Post(s)
    0 Thread(s)

    30 minute timer


    I'm not really a javascript developer I'm a PHP developer but I have a problem I am trying to figure out. I have an online test I need to build with a 30 minute timer. It is written in PHP but i was hoping to user a Javascript timer and carry it over through form submissions.

    Basically my question is, can i feed a PHP variable into javascript? When my page first loads i have the PHP calculating the time plus 30 mins:

    PHP Code:
    $target date("m/d/Y H:i:s"time()+1800); 
    I then want to carry it through 30 questions and display on screen using this javascript:

    <script language="JavaScript">
    TargetDate = "<?php echo $target; ?>";
    BackColor = "palegreen";
    ForeColor = "navy";
    CountActive = true;
    CountStepper = -1;
    LeadingZero = true;
    DisplayFormat = "%%M%% : %%S%% ";
    FinishMessage = "Time is up!";
    The problem I am having is this line: TargetDate = "<?php echo $target; ?>";
    It accepts the date entered manually but not the dynamic date per the variable. Is there a way to make this work? I've written dynamic javascript before using PHP but for some reason this is giving me problems.


    UPDATE: An idea occurred to me while I was writing this. I answered my own question. I made the PHP code produce the javascript and it worked.
    Last edited by Rmazin; Apr 26, 2010 at 07:18. Reason: Answered my own question


Posting Permissions

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