카운트 다운 타이머가있는 양식을 사용하고 있습니다. 타이머가 0이되면 양식이 자동으로 제출됩니다. 그러나 제출이 성공적으로 완료되지 않았습니다. 타이머가 '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>
제출 버튼에서 호출 submit()
하는 <form>
대신의 메소드를 사용하십시오 .
// 'exam' is the ID of your form
document.getElementById('exam').submit();
다음이 작동합니다. 문제는 당신이 당신의의 ID 버튼을 제출 준 것으로 보인다 submit
무시됩니다 submit()
의 방법을 form
. 그래서 버튼 이름 을을 submitButton
하고 그것을 작동합니다.
var timer,
timeleft = 5; // 5 seconds
function time()
{
var minute = Math.floor(timeleft / 60);
var seconds = timeleft % 60;
if (timeleft >= 0)
{
if (minute < 10)
{
minute = "0" + minute;
}
if (seconds < 10)
{
seconds = "0" + seconds;
}
document.getElementById("timer").innerHTML = minute + ":" + seconds;
}
if (timeleft <= 0)
{
clearTimeout(timer);
document.getElementById("exam").submit();
return;
}
timeleft--;
timer = setTimeout(time, 1000);
}
time();
<form id="exam" action="http://www.google.com/search" type="get">
<input type="text" name="q" value="Test">
<input type="submit" value="Submit" id="submitButton">
</form>
<div id="timer"></div>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다