128
rated 0 times
[
133]
[
5]
/ answers: 1 / hits: 16562
/ 11 Years ago, sun, august 4, 2013, 12:00:00
I wrote the following code. With this code pushing Submit button submits the form manually. I have also a timer which I want to auto submit the form after 10 seconds. But it does not work. It counts until 0 and then it does not do anything. Can you please tell me what I am missing or how to change my timer (if there, is the problem)? But I want the user to watch the timer as my 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 to answer the 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 the 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>
More From » php