Wednesday, 13 June 2012

 Set Timer in Online Exam Form

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var tim;

        var min = 90;
        var sec = 60;
        var f = new Date();
        function f1() {
            f2();
            document.getElementById("starttime").innerHTML =+ f.getHours() + ":" + f.getMinutes()+":"+f.getSeconds();

            document.getElementById("endtime").innerHTML = "Your  time is :" + f.toLocaleTimeString();
        }
        function f2() {
            if (parseInt(sec) > 0) {
                sec = parseInt(sec) - 1;
                document.getElementById("showtime").innerHTML = + min + " Minutes ," + sec + " Seconds";
                tim = setTimeout("f2()", 1000);
            }
            else {
                if (parseInt(sec) == 0) {
                    min = parseInt(min) - 1;
                    if (parseInt(min) == 0) {
                        clearTimeout(tim);
                        location.href = "default.aspx";
                    }
                    else {
                        sec = 60;
                        document.getElementById("showtime").innerHTML = "Your Left Time  is :" + min + " Minutes ," + sec + " Seconds";
                        tim = setTimeout("f2()", 1000);
                    }
                }

            }
        }
    </script>
</head>
<body onload="f1()">
    <form id="form1" runat="server">
    <div>
      <table width="100%" align="center">
        <tr>
          <td colspan="2">
            <h2>This is head part for showing timer and all other details</h2>
          </td>
        </tr>
        <tr>
          <td>
          </td>
          <td>Your Start time :<asp:Label ID="starttime" runat="server" BackColor="#CCFFFF"></asp:Label>
          end time :<asp:Label ID="endtime" runat="server" BackColor="#CCFFFF"></asp:Label>
          </td>       
        </tr>
        <tr>
          <td></td>
          <td>Left Time :
           <asp:Label ID="showtime" runat="server" BackColor="#FFCCFF"></asp:Label>
          </td>
        </tr>
        </table>
      <br />
    </div>
    </form>
</body>
</html>

No comments:

Post a Comment