I have a quiz exam in which form submission occurs after the specified time out with an alert message with OK button. Problem is that when time out occurs and after pressing OK button, time out alert is displaying again and again until the page redirected to result page.
I want it to show once and then the page to be get submitted.
Button2 is my submit button and mins is a variable for time in minutes.
Please help me !
Literal1.Text = "<script>$(function(){ var note = $('#note'), ts = new Date(2012, 0, 1),newYear = true; if((new Date()) > ts){ ts = (new Date()).getTime() + " + mins + "*60*1000; newYear = false; } $('#countdown').countdown({ timestamp : ts,callback : function(days, hours, minutes, seconds){ var message = ''; var timer = ''; message += days + ' day' + ( days==1 ? '':'s' ) + ', '; message += hours + ' hour' + ( hours==1 ? '':'s' ) + ', '; message += minutes + ' minute' + ( minutes==1 ? '':'s' ) + ' and '; message += seconds + ' second' + ( seconds==1 ? '':'s' ) + ' <br />'; timer = hours + ':' + minutes + ':' + seconds; note.html(timer); if (minutes.toString() == '0' && seconds.toString() == '0') {$('#note').attr('id', '#note1'); alert('Time up'); $('#Button2').click(); return; } } }); });</script>";
HTML Code
<table>
<tr>
<td style="padding-left:15px;">Time Left :</td>
<td>
<p id="note" style="height: 24px; line-height: 38px;"></p>
</td>
</tr>
</table>
<script type="text/javascript">
var clicked = false;
function DisableButton() {
if (clicked == false) {
clicked = true;
return true;
}
else {
alert("Submitted");
$("#note").attr("id", "#note1");
return false;
}
}
</script>
<asp:Button ID="Button2" runat="server" CssClass="gbutton" Text="Submit" OnClientClick="return DisableButton();" OnClick="Button2_Click" BorderStyle="Outset" />