0

我有一张表格,要求提供四种类型的捐款。用户必须从四种捐赠中选择一种。此外,根据他们选择的一项,他们需要填写相邻的字段(金额)。

如果 A1 已填写 B1 必须填写
如果 A2 已填写 B2 必须填写
如果 A3 已填写 B3 必须填写
如果 A4 已填写 B4 必须填写

...但至少必须填写一个 A。

4

1 回答 1

1

假设您在 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 (client side - pre-post) 验证中更流畅。

于 2012-09-20T09:15:14.913 回答