After timer submit form

F

Floortje

Hi, im an absolute noob at javascript. I copied a timer from a site wich
counts to 5 minutes and then pos up an alert. Is it possibel to
automatically submit the form after I click ok ?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<SCRIPT LANGUAGE = "JavaScript">
<!--
var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer()
{
// Set the length of the timer, in seconds
secs = 300
StopTheClock()
StartTheTimer()
}

function StopTheClock()
{
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}

function StartTheTimer()
{
if (secs==0)
{
StopTheClock()
// Here's where you put something useful that's
// supposed to happen after the allotted time.
// For example, you could display a message:
alert("De tijd is voorbij. Druk op ok en daarna op opslaan")
}
else
{
self.status = secs
secs = secs - 1
timerRunning = true
timerID = self.setTimeout("StartTheTimer()", delay)
}
}
//-->
</SCRIPT>

<body onLoad="InitializeTimer()" >

<h1> Header here</h1>
<p>text</p>
<form name="form1" method="post" action="">
<table width="100%" border="1">
<tr>
<td width="17%">positief</td>
<td width="83%"><div align="right">
<textarea name="positief" cols="100" rows="5"
id="positief"></textarea>
</div></td>
</tr>
</table>
</form>
</body>
</html>
 
R

Rob B

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled document</title>
</head>
<script type="text/javascript">

var timerID = null;
var startsecs = 10;
var secs;

function countdown()
{
window.status = secs-- + ' seconds remaining...';
if (secs < 0)
{
clearInterval(timerID);
if (confirm('Submit the form?'))
document.getElementById('form1').submit();
else timerinit();
}
}

function timerinit()
{
secs = startsecs;
countdown();
timerID = setInterval(countdown, 1000);
}

onload = timerinit;
onunload = function()
{
if (null != timerID)
clearInterval(timerID);
}

</script>
<body>

<h1> Header here</h1>
<p>text</p>
<form id="form1" name="form1" method="post"
action="javascript:alert('submitted')">
<table width="100%" border="1">
<tr>
<td width="17%">positief</td>
<td width="83%"><div align="right">
<textarea name="positief" cols="100" rows="5"
id="positief"></textarea>
</div></td>
</tr>
</table>
</form>
</body>
</html>

Gave the user an opportunity to recycle the timer - you can replace
those lines with:

clearInterval(timerID);
alert('De tijd is voorbij. Druk op ok en daarna op opslaan')
document.getElementById('form1').submit();

Sorry, don't speak Dutch. Timers are annoying btw.
 
F

Floortje

clearInterval(timerID);
alert('De tijd is voorbij. Druk op ok en daarna op opslaan')
document.getElementById('form1').submit();

Sorry, don't speak Dutch. Timers are annoying btw.

It's for an a social psychology experiment. People have 5 minutes to
complete a job in a small team. Then after these 5 minutes a newcomer is
introduced to the team. If someone would take longer to complete the task
the data cannot be compared. Otherwise I would agree .. timers are annoying
:)

Floortje
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top