Java Script passing millisecond timer value to PHP

I have used a Java Scipt millisecond timer, I want to pass the php timer value when the user submits this window. Can anyone help on how to send a JS timer value to PHP?

My JS timer code looks like this: -

I need to pass Seconds.Millisecond a PHP value when a user submits a form.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">

    $(function () {
        $(document).keydown(function (e) {
            return (e.which || e.keyCode) != 116;
        });
    });
</script>
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function () {
      $(document).bind('contextmenu',function(e){
        e.preventDefault();
        alert('Right Click is not allowed');
      });
       });
</script>
<script>
var millisec = 0;
var seconds = 0;
var timer;
function display(){

  if (millisec>=99){
     millisec=0
     seconds+=1
  }
  else
     millisec+=1
     document.d.d2.value = seconds + "." + millisec;
     timer = setTimeout("display()",8);
     }
function startstoptimer() {
  if (timer > 0) {
     clearTimeout(timer);
     timer = 0;
  } else {
     display();
  }
}

</script>
<b>Time Elapsed</b>
<form name="d">
<input type="text" id="time" size="8" name="d2">
</form>

        <script>
            function logout() 
            {
                alert('Times Up, Thank you for taking part in this Quiz!');
                document.forms['QuizQuestions'].submit();
            }

            function StartTimer() 
            {
                t = setTimeout(logout, 80000)//logs out in 15 mins

            }
            function submitThis() {
                document.forms['QuizQuestions'].submit();
            }
        </script>

        </script>

        <body bgcolor="#cceeff" onLoad="startstoptimer();">
        Hello <?php session_start();
        echo $_SESSION['signum'];
            $my_t=getdate(date("U"));
            $datestamp = "$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year], $my_t[hours]:$my_t[minutes]:$my_t[seconds]";
            $_SESSION['StartTime'] = $datestamp;
            $_SESSION['timervals']="<script> document.write(c)</script>";
        ?>, All the best !
        <form name='QuizQuestions' method="post" action="ScoreQuiz.php">
            <pre>
            <font face='sans-serif' size=2>
<input type="hidden" name="time1"  id="time">

Question 1
In the following PHP , what is the correct output:
$x=array("aaa","ttt","www","ttt","yyy","tttt");
$y=array_count_values($x);
echo $y[ttt];
<input type="hidden" name="qq1" value="null">
<input type="radio" name="qq1" value="1"> 2
<input type="radio" name="qq1" value="2"> 3
<input type="radio" name="qq1" value="3"> 1
<input type="radio" name="qq1" value="4"> 4

<hr>Question 2
In PHP Which method is used to getting browser properties?
<input type="hidden" name="qq2" value="null">
<input type="radio" name="qq2" value="1"> $_SERVER['HTTP_USER_AGENT']
<input type="radio" name="qq2" value="2"> $_SERVER['PHP_SELF']
<input type="radio" name="qq2" value="3"> $_SERVER['SERVER_NAME']
<input type="radio" name="qq2" value="4"> $_SERVER['HTTP_VARIENT']

<hr>Question 3
In the following PHP , what is the correct output:
$x=dir(".");
while($y=$x->read())
{
echo $y."
"
}
$y->close();
<input type="hidden" name="qq3" value="null">
<input type="radio" name="qq3" value="1"> display all folder names
<input type="radio" name="qq3" value="2"> display a folder content
<input type="radio" name="qq3" value="3"> display content of the all drives
<input type="radio" name="qq3" value="4"> Parse error

<hr>Question 4
In PHP, which of the following function is used to insert content of 
one php file into another php file before server executes it:
<input type="hidden" name="qq4" value="null">
<input type="radio" name="qq4" value="1"> include[]
<input type="radio" name="qq4" value="2"> #include()
<input type="radio" name="qq4" value="3"> include()
<input type="radio" name="qq4" value="4"> #include{}

<hr>Question 5
In PHP the error control operator is _______
<input type="hidden" name="qq5" value="null">
<input type="radio" name="qq5" value="1"> .
<input type="radio" name="qq5" value="2"> *
<input type="radio" name="qq5" value="3"> @
<input type="radio" name="qq5" value="4"> &

<hr></font>
</pre>
<input type="submit" value="Submit">
</form>

</body>
</html>

      

+3


source to share


1 answer


I have a JS script for you with maximum performance and simple controls:

http://jsfiddle.net/ojzw2hfu/



Put the hidden input on the form, set up the interval function to update the input and feed the timer stop. The value includes Microseconds , but I'll leave that to you to find a way to cut this; -)

var startTime;
var endTime;
var timer;


$(document).ready(function() {
    startTime = performance.now();

    timer = window.setInterval(function() {
        endTime = performance.now();
        $('#timer').text(endTime - startTime);
    });

});

$('#myForm').on('submit', function() {
    window.clearInterval(timer);
    $('#millisecondValueInForm').val(endTime - startTime);
    return false; //remove this later in real script because it prevents form from submitting
});

      

0


source







All Articles