0
下面的函數總是返回false,我想我知道爲什麼,但不知道如何解決它。它驗證的無線電形式是使用循環生成的,我將每個無線電字段的ID設置爲「myfilling」,我認爲這就是我出錯的地方。JS函數總是返回False
功能是:
if(!document.getElementById('myfilling').checked) {
var resultloc=document.getElementById("fillingerror");
resultloc.innerHTML = "<span style='color:red;'>Please select a filling!<span>";
return false;
} else {
var resultloc=document.getElementById("fillingerror");
resultloc.innerHTML = "";
return true;
}
如果我選擇在該領域的第一個單選按鈕,沒有錯誤。但是,如果我選擇其他任何按鈕,則會出現錯誤。我該如何解決?
無線電場與以下產生:
function make_filling_radio($filling)
{
$filling = array("Carne de Casa (shredded beef)", "Carnitas (shredded pork)", "Pulled BBQ Chicken", "Roasted Chili Lime Chicken", "Roasted Veggies");
foreach ($filling as $value){
if (!empty($filling) and (FALSE !== array_search($value, $filling)))
echo "<input type=\"radio\" name=\"filling\" value=\"$value\" id='myfilling'> $value<br>\n";
else
echo "<input type=\"radio\" name=\"filling\" value=\"$value\" id='myfilling'> $value<br>\n";
}
}
向我們展示如何生成它以及相關標記。 – Gabe 2013-04-10 19:48:19
_and我設置每個無線電字段的ID爲「myfilling」_ - id必須是**唯一的** – Andreas 2013-04-10 19:49:23
我意識到它們必須是唯一的,但我該如何解決這個問題?用於生成無線電領域的代碼包括 – 2013-04-10 19:59:13