嵌套ASP验证

时间:2012-09-20 06:10:43

标签: validation asp-classic if-statement

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

如果填写A1,则必须填写B1 如果A2填写B2必须填写
如果A3中填写了B3,则必须填写 如果A4中填写了B4,则必须填写

......但至少必须填写其中一个A.

1 个答案:

答案 0 :(得分: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(客户端 - 帖子前)验证方面更加流畅。