html - javascript countdown timer which posts to server when user hasn't provided answer and zero is hit -


<%@ page import="java.util.list" %>  <html xmlns="http://www.w3.org/1999/xhtml">  <head>      <title>take test</title>      <div id="header">java national benchmark test <strong>(nbt)</strong></div>      <nav id="nav-3">          <link rel="stylesheet" href="css/main.css">          <a class="link-3" href="index.jsp">home</a>          <a class="link-3" href="about.jsp">about</a>          <a class="link-3" href="register.jsp">register</a>          <a class="link-3" href="logoutcontroller">logout</a>      </nav>      <script type="text/javascript" src="javascripts/selectanswer.js"></script>      <script language ="javascript" >          var tim;          var sec = 15;          var f = new date();          function f2() {              if (parseint(sec) > 0) {                  sec = parseint(sec) - 1;                  document.getelementbyid("showtime").innerhtml = "time remaining: "+sec+" secs";                  tim = settimeout("f2()", 1000);              }else {                  if (parseint(sec) == 0) {                      cleartimeout(tim);                  }              }          }      </script>  </head>  <body onload="f2()" >  <div class="taketest">  <form id="taketestform"  method="post" action="taketestcontroller" onsubmit="return validateanswer()">      <div>          <table width="100%" align="center">              <tr>                  <td>                      <div id="showtime" align="right"></div>                  </td>              </tr>              <tr>                  <td>                  </td>              </tr>          </table>      </div>      <%          int questionscounter = (integer) session.getattribute("questionscounter");          int totalsize = (integer) session.getattribute("totalsize");      %>      <p><font color="black">question <%=questionscounter%>/<%=totalsize%></font></p><br>      <%          string quest = (string) session.getattribute("questname");          list<string> options = (list<string>) session.getattribute("optionsstring");      %>      <fieldset>          <legend><font color="black"><%=quest%></font></legend>          <%              (int = 0; i< options.size(); i++){          %>          <p>              <input type="radio" style="color: dodgerblue" name="option" value="<%=options.get(i)%>"><%=options.get(i)%><br>          </p>          <%              }          %>      </fieldset><br>      <input type="submit" value="next question">  </form>  </div>  <div id="footer">      <p align="center"><font color="white">site developed by: nizen molobela <strong>(july 2016)</strong></font></p>  </div>  </body>  </html>

i want move next question if user's allocated time has elapsed. have timed quiz application should provide user time , if time has expired, should move next question. show countdown timer when hits 0, stops , nothing happens. want automatically submit server , move next question.

thanks in advance.

settimeout(function(){ alert("you did not complete question"); }, 3000);

this send user message after 3 seconds (3000ms). without code in question it's hard give specific answer, can integrate version of solution.

further reading - w3schools - window timeout()


Comments