Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,
I m doing online exam project. I want to show countdown timer and calculate time for which I have written following code but it doesn't work. Please help me.
Thanks in advance.

In the form tags:

XML
<input type="hidden" id="timeAllocated" name="timeAllocated" value="30" runat="server" />


then set the timeAlloted control in Page_Load:
C#
if ( !IsPostBack )
        timeAllocated.Value = value-from-database.ToString();

Javascript:
JavaScript
<script language="JavaScript">
<!--
function window::onload()
{
 var timeAlloted = 30;
 if ( document.getElementById('timeAllocated').value.length > 0 )
  timeAlloted = parseFloat(document.getElementById('timeAllocated').value);
 else
  document.getElementById('timeAllocated').value = timeAlloted;
 document.getElementById('timerDisplaySpan').innerHTML =
  '<b>Time Remaining: ' + timeAlloted + " Minutes.</b>";

 // 1000 = 1 second...
 window.setInterval('decrementTimer()', 60000);
}
function decrementTimer()
{
 var timeAlloted = parseFloat(document.getElementById('timeAllocated').value);
 timeAllote-;
 document.getElementById('timeAllocated').value = timeAlloted;
 document.getElementById('timerDisplaySpan').innerHTML =
  '<b>Time Remaining: ' + timeAlloted + " Minutes.</b>";
}
// -->;
</script>
Posted
Updated 26-Jul-10 19:07pm
v2
Comments
Ankur\m/ 27-Jul-10 1:10am    
Is it "timeAllote-;" or a typo.
It should be "timeAlloted--;"

1 solution

1. "timeAllote-;" would be " timeAllote--;"
2. Where/When do you call decrementTimer?

Lastly, what didn't work. Any error?
 
Share this answer
 
Comments
aparnaChandras 27-Jul-10 2:14am    
It doesn't show time
Sandeep Mewara 27-Jul-10 2:27am    
When did you set the visibility of 'timerDisplaySpan'? I mean is it always visible in your html? Further, why do you want to change the full InnerHTMl when changing just the time label would do for you?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900