29 September 2021

How to create quiz timer (Left time) in PHP?

Create quiz timer in PHP. 

<!DOCTYPE html>

<html lang="en">

<body>

<center>

<div class="time" id="navbar">Time left :<span id="timer"></span></div>

<button class="button" id="mybut" onclick="myFunction()">START QUIZ</button>

</center>

<div id="myDIV" style="padding: 10px 30px;">

<form action="result.php" method="post" id="form"> 


</form>

</div>

<script>

function myFunction() {

var x = document.getElementById("myDIV");

    var b = document.getElementById("mybut");

    var x = document.getElementById("myDIV");

if (x.style.display === "none") { 

b.style.visibility = 'hidden';

x.style.display = "block";

startTimer();

}

}

window.onload = function() {

  document.getElementById('myDIV').style.display = 'none';

};

</script>

<?php

$settime = 0 . ':' . 01 . ':' . 06;

?>

 <script type="text/javascript">

document.getElementById('timer').innerHTML = '<?php echo $settime; ?>';

  //06 + ":" + 00 ;

function startTimer() {

  var presentTime = document.getElementById('timer').innerHTML;

  var timeArray = presentTime.split(/[:]+/);

  var h = timeArray[0];

  var m = timeArray[1];

  var s = checkSecond((timeArray[2] - 1));

  if(s==59){

  m=m-1

   if(m==0 && h>0){

h=h-1

m=59

  } 

  }

    document.getElementById('timer').innerHTML =

    h + ":" + m + ":" + s;

  if(h==0 && m==0 && s==0){

  //document.getElementById("form").submit();

  console.log('Time is Done.');

  if(s==0){

return true;

  }

  }

 setTimeout(startTimer, 1000);

}

function checkSecond(sec) {

  if (sec < 10 && sec >= 0) {sec = "0" + sec}; // add zero in front of numbers < 10

  if (sec < 0) {sec = "59"};

  return sec;

 // if(sec == 0 && m == 0){ alert('stop it')};

}

function checkmintue(min) {

  if (min < 10 && min >= 0) {min = "0" + min}; // add zero in front of numbers < 10

  if (min < 0) {min = "59"};

  return min;

 // if(min == 0 && h == 0){ alert('stop it')};

}

</script>

</body>

</html>

No comments:

Post a Comment

How to create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...