Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用document.getElementById无法处理php表单_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 使用document.getElementById无法处理php表单

Javascript 使用document.getElementById无法处理php表单,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我这里有一个使用javascript的php定时器,我的问题是 这一行当我的总秒数达到0时,我的表单名为QUICE并不是自动提交的,任何人都可以在这里找到问题所在 顺便说一句,我的代码没有错误 if(total_seconds <=0){setTimeout('document.getElementById("quiz").submit()',1); <div style="font-weight: bold" id="quiz-time-left"> <script

我这里有一个使用javascript的php定时器,我的问题是

这一行当我的总秒数达到0时,我的表单名为QUICE并不是自动提交的,任何人都可以在这里找到问题所在

顺便说一句,我的代码没有错误

if(total_seconds <=0){setTimeout('document.getElementById("quiz").submit()',1);

<div style="font-weight: bold" id="quiz-time-left">

<script type="text/javascript">
var max_time = <?php echo $total_timer1 ?>*60;
var c_seconds  = 0;
var total_seconds =max_time;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
function init(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
setTimeout("CheckTime()",999);
}
function CheckTime(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds' ;
if(total_seconds <=0){
setTimeout('document.getElementById("quiz").submit()',1); <-- **my problem**

    } else
    {
total_seconds = total_seconds -1;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",999);
}

}
init();
</script>
</div>

if(total_secondssetTimeout将函数作为第一个参数,后跟时间延迟

函数delayAlert(){
警报(“已调用setTimeout”);
}

setTimeout(delayAlert,1000);
setTimeout期望函数作为第一个参数,后跟时间延迟

函数delayAlert(){
警报(“已调用setTimeout”);
}

setTimeout(delayAlert,1000);
setTimeout({document.getElementById(“quick”).submit()},1)
删除上面一行的单引号..setTimeout(document.getElementById(“quick”).submit(),1);像这样吗?抱歉,像这样使用一个
匿名函数(“quick”).submit()},1)
setTimeout(function(){document.getElementById(“quick”).submit()},1)尝试了这个仍然不起作用。很难看到这里发生了什么。尝试显示客户端代码(即在执行PHP之后)并利用空白空间对其进行格式化,使其可读。
setTimeout({document.getElementById(“quick”).submit()},1)
删除上面一行的单引号..setTimeout(document.getElementById(“quick”).submit(),1);像这样吗?抱歉,使用类似这样的
匿名函数-
setTimeout(function(){document.getElementById(“quick”).submit()},1)
setTimeout(function(){document.getElementById(“quick”).submit()}),1)尝试了这个仍然不起作用。很难看到这里发生了什么。尝试显示客户端代码(即在执行PHP之后),并利用空白对其进行格式化,使其可读。用代码定义函数并将其传递给setTimeout函数。函数submitMyform(){document.getElementById(“quick”).submit();}setTimeout(submitMyform,1);仍然不工作,或者我还需要将该脚本放在submit行下吗?或者不关心您将Javascript放在哪一行这是最佳做法,但它也接受要计算的字符串,所以这不是问题。用代码定义一个函数并将其传递给setTimeout函数。函数submitMyform(){document.getElementById(“quick”).submit();}setTimeout(submitMyform,1);仍然不工作,或者我还需要将该脚本放在submit行下吗?或者不关心您将JavaScripts放在哪一行这是最佳做法,但它也接受要计算的字符串,所以这不是问题所在。
<form action="result.php" method="post" id='quiz'>


<?php
$username=$_SESSION['username'];
$query1 = mysql_query("SELECT * FROM student WHERE username='$username'");
$row1 = mysql_fetch_assoc($query1);
$id1 = $row1['id'];

$query = mysql_query("SELECT * FROM timer WHERE s_id='$id1' AND q_id='$id' ");
$row = mysql_fetch_assoc($query);

$currenttime = date ("h:i:sa");
$q_start10 = strtotime ($currenttime);
$q_time = $row['q_time'];
$q_endtime = $row['q_endtime'];
$total_timer = $q_endtime - $q_start10; 
$total_timer1 = $total_timer / 60;



?>


    <font size="6">
<div style="font-weight: bold" id="quiz-time-left"></div>

<script type="text/javascript">
var max_time = <?php echo $total_timer1 ?>*60;
var c_seconds  = 0;
var total_seconds =max_time;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
function init(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
setTimeout("CheckTime()",999);
}
function CheckTime(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds' ;
if(total_seconds <=0){
    setTimeout(function(){document.getElementById("quiz").submit()},1000)

    } else
    {
total_seconds = total_seconds -1;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",999);
}

}
init();
</script>

</font>
<br>

<br>
<?php
$score = 0;
$tbl_name2="a_quiz"; // Switch to table "forum_answer"
$sql2="SELECT * FROM $tbl_name2 WHERE q_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
$q_question = $rows['q_question'];
?>

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr style='overflow:hidden; word-wrap:break-word;'>
<p hidden>
    <input type="text" name="q_id" value="<?php echo $rows['q_id'];?>">
    </p>
<td bgcolor="lightgreen"><strong>Question:</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen" style="max-width: 1000px;"><?php echo $rows['q_question']; ?></td>
</tr>

<tr>
<td bgcolor="lightgreen"><strong>A</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['a_id']; ?>" value="a"><?php echo $rows['a'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>B</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['a_id']; ?>" value="b"><?php echo $rows['b'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>C</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['a_id']; ?>" value="c"><?php echo $rows['c'] ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>D</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['a_id']; ?>" value="d"><?php echo $rows['d'] ?></td>
</tr>


</table></td>
</tr>
<hr>
</table><br>
 <?php
}
?>
<?php

$connection=mysql_connect('localhost', 'root','');
mysql_select_db('thesis');

$username= $_SESSION['username'];


$query6 = mysql_query("SELECT * FROM student WHERE username='$username'");
$row6 = mysql_fetch_assoc($query6);
$s_id = $row6['id'];
$fname = $row6['f_name'];
$mname = $row6['m_name'];
$lname = $row6['l_name'];
$email = $row6['email'];
$position = $row6['position'];
    ?>
<p hidden>
<input type="text" name="s_id" value="<?php echo $s_id ?>">
</p>
<input type="submit" name="submit" value="Submit Answer" class="btn">
</form>