php - Auto submit form using timer -
i wrote following code. code pushing submit button submits form manually. have timer want auto submit form after 10 seconds. not work. counts until 0 , not anything. can please tell me missing or how change timer (if there, problem)? want user watch timer example
<!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" /> <script type="text/javascript"> function countdown(secs,elem) { var element = document.getelementbyid(elem); element.innerhtml = "<h2>you have <b>"+secs+"</b> seconds answer questions</h2>"; if(secs < 1){ cleartimeout(timer); document.getelementbyid('myquiz').submit(); } secs--; var timer = settimeout ('countdown('+secs+',"'+elem+'")',1500); } </script> <div id="status"></div> <script type="text/javascript">countdown(5,"status");</script> <title>questionnaire</title> <style type="text/css"> span {color: #ff00cc} </style> </head> <body> <h1>please complete following survey</h1> <form name="quiz" id ="myquiz" method="post" action="includes/process.php"> first name: <input type="text" name="firstname" id="fname"/> <p></p> last name: <input type="text" name="lastname" id="lname"/> <p></p> <input type="submit" name="submit" value="go"></input> <input type="reset" value="clear all"></input> </form> </body> </html>
don't this:
var timer = settimeout ('countdown('+secs+',"'+elem+'")',1500);
in countdown
. every 1500 you're calling countdown
again.
put @ bottom of page (before closing body
tag)
<script type="text/javascript"> secs = 10; timer = setinterval(function () { var element = document.getelementbyid("status"); element.innerhtml = "<h2>you have <b>"+secs+"</b> seconds answer questions</h2>"; if(secs < 1){ clearinterval(timer); document.getelementbyid('myquiz').submit(); } secs--; }, 1000)
btw: validate()
declared ?
didn't test it, should trick.
Comments
Post a Comment