提交时的Checkbox ASP验证

时间:2012-03-26 12:31:35

标签: html asp-classic vbscript

我有一个包含3个文本字段和3个复选框的表单。我已经实现了VB脚本验证,因此如果用户提交表单并留下空白,用户将返回到已填写字段的表格。也就是说,这不适用于chackboxes。

这是我用于复选框的代码我在代码中执行代码“”

<input type="checkbox" name="ClaimSection_ActivityProof"  id="ClaimSection_ActivityProof"  value="<%=Request.Form("ClaimSection_ActivityProof")%>" style="width:20px" />
<input type="checkbox" name="ClaimSection_InvoicesPayableByPartner" id="ClaimSection_InvoicesPayableByPartner" value="<%=Request.Form("ClaimSection_InvoicesPayableByPartner")%>"  style="width:20px" />
<input type="checkbox" name="ClaimSection_InvoicesPayableByGFI" id="ClaimSection_InvoicesPayable" value="<%=Request.Form("ClaimSection_InvoicesPayable")%>" style="width:20px" />

要缩短sotry short,如果用户选中2个复选框,则提交表单,当他再次重定向回表单时,复选框将保持选中状态。我该怎么办呢?

3 个答案:

答案 0 :(得分:1)

我认为你应该回发你的表格数据。请尝试以下链接:

http://www.motobit.com/tips/detpg_post-binary-data-url/

http://www.tek-tips.com/viewthread.cfm?qid=1281365

这些链接提供了一些使用post方法发送表单数据的示例代码。不幸的是我没有设置IIS,所以我无法尝试这些例子。在第一个观点,这个想法可行。

答案 1 :(得分:1)

value属性与确保checbox在加载/回发时保持其已检查状态无关。

要执行此操作,您需要检查它们是否在提交时检查(请求中的“on”),如果“on”则设置checked =“checked”。

示例:

<%

if len(request.form("ClaimSection_ActivityProof")) > 0 then
    ClaimSection_ActivityProof_Checked = " checked=""checked"""
else
    ClaimSection_ActivityProof_Checked = ""
end if

%>

<input type="checkbox" name="ClaimSection_ActivityProof"  id="ClaimSection_ActivityProof" <%=ClaimSection_ActivityProof_Checked %> style="width:20px" />

希望这是有道理的。

学家

答案 2 :(得分:1)

使用相同的名称命名(或组)复选框(我假设它们都是相关的ClaimSection事项) 因此,您可以将它们全部命名为&#34; ClaimSection&#34;。只需确保为每个人分配自己独特的值!

实施例

<input type='checkbox' name='ClaimSection' value='ActivityProof'>
<input type='checkbox' name='ClaimSection' value='InvoicesPayableByPartner'>
<input type='checkbox' name='ClaimSection' value='InvoicesPayableByGFI'> 

使用此命名,如果您的用户检查了2个以上的复选框,您将以逗号分隔的方式获得相应的值。 因此,如果您的用户检查最后2个复选框,您将获得&#34; InvoicesPayableByPartner,InvoicesPayableByGFI&#34;作为回报。

现在您知道这一点,通过与您在请求中得到的内容进行比较,很难设置一堆if分支来处理已检查与未检查的内容(&#34; ClaimSection&#34 ;)

以下内容可以帮助您找到正确的方向..

dim submitted_ClaimSections 
submitted_ClaimSections = request("ClaimSection") 
submitted_ClaimSections = "," & submitted_ClaimSections & ","

//handle the ActivityProof checkbox checked_or_not ="" 
if  instr(submitted_ClaimSections,"," & "ActivityProof" & ",")>0 then       
    checked_or_not = "checked" 
end if 
Response.write "<input type='checkbox' name='ClaimSection' value='ActivityProof' " & checked_or_not & "> ActivityProof" 

//handle the InvoicesPayableByPartner checkbox checked_or_not ="" 
if instr(submitted_ClaimSections,"," & "InvoicesPayableByPartner" & ",")>0 then     
    checked_or_not = "checked" 
end if 
Response.write "<input type='checkbox' name='ClaimSection' value='InvoicesPayableByPartner' " & checked_or_not & "> InvoicesPayableByPartner" 


//handle the InvoicesPayableByGFI checkbox checked_or_not ="" 
if instr(submitted_ClaimSections,"," & "InvoicesPayableByGFI" & ",")>0 then
    checked_or_not = "checked" 
end if 
Response.write "<input type='checkbox' name='ClaimSection' value='InvoicesPayableByGFI' " & checked_or_not & "> InvoicesPayableByGFI"