ページの最後に結果を表示する必要があります。を使用してフィードバックを追加しようとすると、getElementById()
常に返さnull
れます。範囲外だと思います。それを修正する方法はありますか?
これは私のJavaScript関数です。
function handler(var1,quizId,isCorrect,score,name,email) {
alert(var1);
//var id = parseInt(quizId);
quizId++;
var points=10;
if(isCorrect=='true'){
score=score+points;
document.getElementById("result").innerHTML="Correct<br/>";
var string_url="quiz.php?qusId="+quizId+"&score="+score+"&name="+name+"&email="+email;
setTimeout(function() {
window.location = string_url
}, 5000);
}
else{
document.getElementById("result").innerHTML="Wrong<br/>";
var string_url="quiz.php?qusId="+quizId+"&score="+score+"&name="+name+"&email="+email;
setTimeout(function() {
window.location = string_url
}, 5000);
}
}
これは私のPHPコードです。
<body >
<?php
$qusId=$_GET['qusId'];
$passscore=70;
if(isset($_GET['score'])){
$score=$_GET['score'];
}
else{
$score=0;
}
if(isset($_POST['name'])){
$name=$_POST['name'];
}
else{
$name=$_GET['name'];
}
if(isset($_POST['email'])){
$email=$_POST['email'];
}
else{
$email=$_GET['email'];
}
?>
<form action="email.php?name=<?php echo $name; ?>&email=<?php echo $email;?>&score=<?php echo $score;?>" method="POST">
<?php
$result = select("SELECT * FROM questions WHERE question_id='$qusId'");
//$row = mysql_fetch_array($result);
?>
<?php
$i=$_GET['qusId'];
if($qusId<11){
while($row = mysql_fetch_array($result))
{
?>
<table width="581" height="175" border="0" align="center">
<tr>
<td><h4><?php echo $i.'.' .$row['questions']; ?></h4>
<?php $i++; ?>
</td>
</tr>
<tr>
<td>
<?php $qId=$row['question_id'];?>
<?php
$result1=select("SELECT * FROM answers WHERE questionId='$qId' ORDER BY RAND()");
while($row1=mysql_fetch_array($result1)){
?><input type="radio" name="answers" value="<?php echo $row1['answers'];?>" onclick="handler('<?php echo $row1["feedback"]; ?>',<?php echo $qusId;?>,'<?php echo $row1["isCorrect"]; ?>',<?php echo $score;?>,'<?php echo $name; ?>', '<?php echo $email; ?>')
"/ ><?php echo $row1['answers']; ?><br/>
<?php
} ?>
</td>
</tr>
</table>
</form>
<p>
<?php
}
}
else{
?>
</p>
<p>
<table>
<tr><td>
Your Name:<?php echo $name;?><br /><br/>
Your Email:<?php echo $email;?><br /><br/>
Pass Score:<?php echo $passscore;?><br /><br/>
Your Score:<?php echo $score;?><br/><br/>
<?php if($score>=$passscore){?>
Result:Congratulation! You Have passed the questionnaire.<br/><br/
<?php }else{ ?>
Result:Sorry! Please <a href="/uaquiz/index.php">Try again</a><br/>
<?php } ?>
</p>
</td></tr>
<tr><td><input class="submit" type="submit" value="Send Result" /></td></tr>
</table>
</form>
<table id="feedback">
<tr>
<td id="questions">1. What is Union Assurance brand pay off line<br/>
2. What does the Union Assurance brand colour orange signify<br/>
3. What does the Union Assurance brand colour grey signify<br/>
4. Union Assurance is baked by <br/>
5. Union Assurance Brand is built on the platform of <br/>
6. Union Assurance brand promise trust is delivered through <br/>
7. Union Assurance Symbol depicts<br/>
8. What’s Union Assurance brand ranked in the LMD Brands.<br/>
9. What’s Union Assurance brand value?<br/>
10. What is the best way to build your brand <br/> </td>
<td id="result">aaa</td>
</tr></table>
<?php
}
?>
</body>