我有一個表單要求四種類型的捐贈。用戶必須選擇四項捐贈中的一項。另外,根據他們選擇哪一個,他們需要填寫相鄰的字段(金額)。嵌套的ASP驗證
如果A1被填充在B1必須
填充如果A2被填充在B2必須填寫
如果A3被填充在B3必須填寫
如果A4被填充在B4必須填寫
...但至少A的一個必須填寫
我有一個表單要求四種類型的捐贈。用戶必須選擇四項捐贈中的一項。另外,根據他們選擇哪一個,他們需要填寫相鄰的字段(金額)。嵌套的ASP驗證
如果A1被填充在B1必須
填充如果A2被填充在B2必須填寫
如果A3被填充在B3必須填寫
如果A4被填充在B4必須填寫
...但至少A的一個必須填寫
假設你ASP驗證後是(即後門柱),你可以做這樣的事情:
dim A1 : A1 = trim(request.form("A1"))
dim A2 : A2 = trim(request.form("A2"))
dim A3 : A3 = trim(request.form("A3"))
dim A4 : A4 = trim(request.form("A4"))
dim B1 : A1 = trim(request.form("B1"))
dim B2 : B2 = trim(request.form("B2"))
dim B3 : B3 = trim(request.form("B3"))
dim B4 : B4 = trim(request.form("B4"))
dim ValidationError : ValidationError = ""
if A1 <> "on" and A2 <> "on" and A3 <> "on" and A4 <> "on" then
ValidationError = "Please select at least one option"
else
if A1 = "on" and B1 = "" then ValidationError = "You selected A1, please complete the amount"
if A2 = "on" and B2 = "" then ValidationError = "You selected A2, please complete the amount"
if A3 = "on" and B3 = "" then ValidationError = "You selected A3, please complete the amount"
if A4 = "on" and B4 = "" then ValidationError = "You selected A4, please complete the amount"
end if
if ValidationError <> "" then
response.write(ValidationError)
else
'#### All OK
end if
但是像這樣的東西通常會在javascript(客戶端 - 預發佈)驗證中變得很滑。
看起來不像有效的經典ASP代碼... –
@RicoSuave好斑點,昏暗的地方,確實在完整的vb中,改爲vba – HeavenCore
有什麼問題? [你有什麼嘗試?](http://mattgemmell.com/2008/12/08/what-have-you-tried/),你想驗證表單輸入字段,你是否驗證他們在客戶端或服務器端? – user1406062