0

Sorry, I don't know codes much.

I want to make a quiz exam were student will submit his/her answer between a limited time.

I tried to use setTimeout(); unfortunately didn't worked for me. The page was refreshing but I didn't get anything form echo $_POST['name'];

My form-

<form action="result.php" method="POST">
   <input type="text" name="answer" >
   <input type="submit" name="submit" >
</form>

If the student can't finish the answer between 10 Sec, the page will stop him to type anyting and will take him to result.php where he can see the answers he gave.

result.php

<?php

echo $_POST['answer'];

?>

Hope you will solve it for me.

2 Answers2

1

You can do this in jquery like:

setTimeout(function() {   
    //call click event after a certain time
    $('input[name="submit"]').click();
}, 10000);    // time is ms
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
0

Blueblazer172's answer was correct. But give your form an id then submit or else js will submit all the forms in the page

html

<form id="anything" action="result.php" method="POST">
   <input type="text" name="answer" >
   <input type="submit" name="submit" >
</form>


JS

setTimeout(function(){
    $('form').submit();
}, 10000);
Jawad Ahbab
  • 1,462
  • 1
  • 19
  • 31