這個腳本的功能主要是我希望如何:當收音機複選框沒有被選中時發出警報。但是,如果所有按鈕都被選中,我需要它提交的表單......這就是我掛斷的地方。現在,如果所有字段和按鈕都被選中,那麼我仍然會收到一個警報,其中包含var alertMsg。有任何想法嗎?經過驗證的Javascript表單提交
function submitform() {
var sizeChoice = ""
var size = document.store.on1.length
var fontChoice = ""
var len = document.store.on2.length
var materialChoice = ""
var material = document.store.on3.length
var treatmentChoice = ""
var treatment = document.store.on4.length
var a = document.forms["store"]["item_name"].value;
var alertMsg = "Please Choose a:"
for(i = 0; i < size; i++) {
if(document.store.on1[i].checked) {
sizeChoice = document.store.on1[i].value
}
}
for(i = 0; i < len; i++) {
if(document.store.on2[i].checked) {
fontChoice = document.store.on2[i].value
}
}
for(i = 0; i < material; i++) {
if(document.store.on3[i].checked) {
materialChoice = document.store.on3[i].value
}
}
for(i = 0; i < treatment; i++) {
if(document.store.on4[i].checked) {
treatmentChoice = document.store.on4[i].value
}
}
if(a == null || a == "") alertMsg += "\n" + "Name" + "\n";
if(sizeChoice == "") {
alertMsg += "Size" + "\n"
}
if(fontChoice == "") {
alertMsg += "Font" + "\n"
}
if(materialChoice == "") {
alertMsg += "Material" + "\n"
}
if(treatmentChoice == "") {
alertMsg += "Treatment" + "\n"
} {
alert(alertMsg)
};
return false;
document.forms["form"].submit();
};
你在最後一個'if'語句後面有一個語法錯誤,看起來像是一個額外的括號。也就是說,你知道'我'是全球性的,你可能想在某個地方定義它。 – elclanrs