0

如果我以 mysql_* 格式询问,我很抱歉,因为这是我现在正在使用的。我仍然希望你们能帮助我。

所以我的问题是,一旦提交了其中一行单选按钮未选中的表单,我就会尝试显示错误。但是,根据我的代码,它仅出现在特定行上,而不是顶部的单个消息,因为我认为我已将其包含在 While-Loop 中。各位大神能不能给个方法建议一下?无论是javascript还是函数,我都很好。我只是不知道该怎么做:P。

这是我的代码:

while($fetch=mysql_fetch_array($query)){

//DISPLAY ALL ANSWERS
if(isset($_POST['voted'])){
    if(in_array($_POST['score('.$fetch['questionID'].')'], $radioValue)){
        echo "<tr>Question no. ",$fetch['questionID'],": ",
        $_POST['score('.$fetch['questionID'].')'],"<br></tr>";
    }
    else{
        echo "<center><font color=red>All fields are required</font><br><br>
        <input type='button' name='return' value='Return' onclick='history.go(-1)'><br>";
        exit();
    }
}

//DISPLAYS QUESTIONS WITH QUESTION NUMBER
echo "<tr align=left><th><font face='Courier New,arial' size=2px>".$fetch["questionID"].". ".$fetch["question"]."<br>
    <td><font face='Courier New,arial' size=2px>";


//DISPLAYS RADIO BUTTONS FROM 1 to 5    
for($i = 1; $i < 6; $i++){
    echo "<input type=radio name='score(".$fetch["questionID"].")' value=",$i," >"; echo $i;
}   

}

4

2 回答 2

1

我会在while循环中放置一个变量来检查错误。类似于以下内容:

$validationFailed = false;
while($fetch=mysql_fetch_array($query)){

//DISPLAY ALL ANSWERS
if(isset($_POST['voted'])){
if(in_array($_POST['score('.$fetch['questionID'].')'], $radioValue)){
    echo "<tr>Question no. ",$fetch['questionID'],": ",
    $_POST['score('.$fetch['questionID'].')'],"<br></tr>";
}
else{
    $validationFailed = true;
    exit();
}
}

//following should be outside the while loop.
if($validationFailed) {
    echo "<center><font color=red>All fields are required</font><br><br>
    <input type='button' name='return' value='Return' onclick='history.go(-1)'><br>";
}
于 2013-03-11T10:28:32.053 回答
0

首先请为单选按钮使用相同的名称,值会有所不同。现在在提交时尝试此代码,如果为真,然后发布您的表单,否则显示错误消息

var iz_checked = true;
$('input').each(function(){
   iz_checked = iz_checked && $(this).is(':checked');
});
于 2013-03-11T10:29:36.037 回答