2014-02-06 50 views
0

我正在使用名爲「timer.To」的jQuery插件來定時考試。現在我想要的是當計時器達到0時,單選按鈕的值將被存儲在一個數組上,然後將其與正確的答案相比較w/c也保存在一個數組上,計算正確答案的數目,然後提交給此數據庫並移動到下一個頁面.. 這裏是定時器的代碼..如何將單選按鈕值存儲在數組中並與正確答案進行比較?

<script type="text/javascript"> 
$(document).ready(function() { 
    $('#countdown').timeTo(500, function() { // what should I do? 
     }); 
}); 
</script> 

這是因爲,它是在PHP創建一個外部文件形式:

$Element = 0; 
$countme = 0; 
$resulta = mysql_query("SELECT * FROM tblquestions WHERE subject = '".$subject."' ORDER BY rand()"); 
echo '<form action="" method="POST" > '; 
    echo '<fieldset style="border: 2px solid grey; border-radius:7px; -moz-box-shadow:0 0 8px #666; -webkit-box-shadow:0 0 8px #666; box-shadow:0 0 8px #666;">'; 
    echo '<table width ="100%" height="100%" style="border: 2px solid grey; " >'; 

    while($row = mysql_fetch_array($resulta)) 
    { 
       $Data [$Element] = $row['CorrectAns']; // ARRAY WHERE THE CORRECT ANSWER IS SAVE 

     echo "<tr style='border: 2px solid grey;'>"; 
     echo "<td style='border: 2px solid grey; font-weight:bold; width:130px;'>Question # " .$countme."</td>"; 
     echo "<td colspan='3' style='border: 2px solid grey; font-weight:bold;'>".$row['Questions']."</td>"; 
     echo "</tr>"; 

    $troll= 'QID'. $countme; //USED FOR NAMING RADIO BUTTON.. 

     echo "<tr style='border: 2px solid grey;'>"; 
     echo "<td style='border: 2px solid grey;' ><label><input type='radio' name='".$troll."' value='".$row['choice4']."'>".$row['choice4']."</label></td>"; 
     echo "<td style='border: 2px solid grey;'><label><input type='radio' name='".$troll."' value='".$row['choice2']."'>".$row['choice2']."</label></td>"; 
     echo "<td style='border: 2px solid grey;'><label><input type='radio' name='".$troll."' value='".$row['choice3']."'>".$row['choice3']."</label></td>"; 
     echo "<td style='border: 2px solid grey;'><label><input type='radio' name='".$troll."' value='".$row['choice1']."'>".$row['choice1']."</label></td>"; 
     echo "</tr>"; 
    $rawr[$countme]= $row['choice4']; 
    $countme=$countme+1; 
    $Element++; 

     } 
$correct = implode('', $Data); // VAR CONTAINING THE ARRAY OF CORRECT ANSWER 
    echo "</table>"; 
    echo '</fieldset>'; 
     echo '<input type="submit" name="Submit" class="art-button" value="NEXT --> " /> 
    echo '</form>'; 

提交按鈕用於在用戶完成時間之前完成提交。請分享你的想法與此,謝謝:D

回答

0
<script type="text/javascript"> 
$(document).ready(function() { 
    $('#countdown').timeTo(500, function() { // call this function here. 

validate_answer(); 
     }); 
}); 


function validate_answer() 
{ 
// take your $data variable and check for correct answer 
//passing your array through loop. and find marks and display it. 
} 
</script> 

也調用validate_answer()函數提交。

+0

函數validate_answers()的內容是什麼? 函數validate_answer() {var i = 0; i <= answer.lenght ;; i ++) { $ Data [i] == ??我如何獲得單選按鈕值? //你能以某種方式告訴我如何? 還有,我如何在javascript中包含一個php數組..我最後一次嘗試它..它在console.log中沒有任何返回.. } } – Nixxhalle

相關問題