私はカウントダウンタイマー付きのフォームを使用しています。タイマーがゼロになると、フォームは自動的に提出されます。しかし、提出はうまくいっていません。タイマーが「0」になると、タイマーは停止します。私はここに私のコードを与えている。タイマーがゼロになると、フォームは送信されません。
私がやった間違いを見つけてください。コードの下
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input[type='checkbox']").change(function() {
if ($(this).is(":checked"))
{
$(this).closest("thead").addClass("redBackground");
}
else
{
$(this).closest('thead').removeClass("redBackground");
}
});
});
</script>
<script language="javascript">
function over() {
document.getElementById("submit").disabled = true;
}
function time() {
var minute = Math.floor(timeleft/60);
var seconds = timeleft % 60;
if (timeleft <= 0)
{
clearTimeout(timer);
document.getElementById("submit").submit();
}
else
{
if (minute < 10)
{
minute = "0" + minute;
}
if(seconds < 10)
{
seconds = "0" + seconds;
}
document.getElementById("timer").innerHTML = minute + ":" + seconds;
}
timeleft--;
var timer = setTimeout(function(){time()}, 1000);
}
</script>
<style>
</head>
<body onload="time()">
<script>
var timeleft = 2 * 60;
</script>
<?php
include('connect.php');
session_start();
$sql = "select * from test";
$query = mysql_query($sql);
$i = 0;
echo "<div id='timer'></div>";
echo"<form method='post' action='test2.php' name='exam' id='exam'>";
while($row = mysql_fetch_array($query))
{
echo "<center><table border='0'>";
echo "<thead>";
$i++;
echo "<td colspan='4'>";
echo "<input type='checkbox' id='$i' name='$i'>";
echo $i . ".";
echo " ";
echo $row['question'];
echo "</td>";
echo "</thead>";
echo "<tr>";
echo "<td class='ans'>";
echo "<input type='radio' name='ans$i' value='A'>";
echo "(A)  ";
echo $row['opt1'];
echo "</td>";
echo "<td class='ans'>";
echo "<input type='radio' name='ans$i' value='B'>";
echo "(B)  ";
echo $row['opt2'];
echo "</td>";
echo "<td class='ans'>";
echo "<input type='radio' name='ans$i' value='C'>";
echo "(C)  ";
echo $row['opt3'];
echo "</td>";
echo "<td class='ans'>";
echo "<input type='radio' name='ans$i' value='D'>";
echo "(D)  ";
echo $row['opt4'];
echo "</td>";
echo "</tr>";
echo "</table></center>";
echo "<br>";
}
echo "<center><input type='submit' name='submit' value='submit' id='submit' onclick='over();'></center>";
echo "</form>";
$_SESSION["qs"] = $i;
?>
</body>
</html>
試しに変更してください。document.getElementById( "submit"); submit(); 'to' document.getElementById( "exam")。submit(); ' –
私はまだ両方のケースを試してみました – PAVAN
コンソールに何かエラーがありますか? (ブラウザのコンソールを確認してください) –