2012-01-06 61 views
0

复选框我有一个复选框如何实现在传统的ASP

<td><strong>Online Ordering: </strong></td> 
<td><input type="checkbox" name="OnlineOrdering" value="<%=OnlineOrdering%>" <% if OnlineOrdering = True then response.write "checked='Checked'" end if %>/></td> 

我如何捕捉复选框是否被选中或取消选中提交表单时?

OnlineOrdering = request.form("OnlineOrdering") 

这不起作用?

回答

2

这应该指定一个真/假的变量OnlineOrdering:

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then 
    OnlineOrdering = (Request.Form("OnlineOrdering") <> "") 
End If 
+0

得益于优秀的,从来没有 – Beginner 2012-01-06 15:14:41

+0

这是一个经验:)之前,传统的ASP工作。我相信你已经完成了,但代码会评估发布的值OnlineOrdering是否不为空 - 如果它不是[空白],则检查它,如果它是空白的,那么它是未选中的。 – akiller 2012-01-06 15:18:49

1

我发现这个职位,因为我试图解决同样的问题。我有一个似乎很好的解决方案。

在HTML表单中,创建动态生成的复选框。下面使用的this_box_id的值可以是任何唯一的数字。在我的情况下,它是SQL数据库中该问题的主键(自动编号)。动态生成与相关的隐藏字段的复选框:

<input type="hidden" name="check_box_indicator" value="<%=this_box_id%>"> 
<input type="checkbox" name="box_id<%=this_email_selection_id%>" 
value="<%=this_box_id%>"> 

当ASP返回此值,它会返回多个值check_box_indicator。下面是一个示例查询字符串片段:

...&check_box_indicator=78&box_id78=78&check_box_indicator=98&check_box... 

在下一页上,ASP将读取表单数据。它会找到每一个check_box_indicator并且它是有价值的。该值可用于检查关联复选框的值。如果该复选框返回,则会进行检查,如果没有,您会知道它未被检查。在上面的示例中,复选框78已被选中,所以box_id78值被传递,而复选框98不是,box_id98未被发送。这是使用这个的代码。

For Each this_box_id In Request.Form("check_box_indicator") 'check EVERY box' 

    box_state = Request.Form("box_id"&this_box_id) 'collect passed values only' 

    if box_state > 0 then 
     store_value = "y" 
    else 
     store_value = "n" 
    end if 

    ' you now have the this_box_id number identifying this item in the DB, ' 
    ' the value of the check box, if it was passed ' 
    ' and a definite y or n value ' 

Next 

随着例如查询字符串,你会得到78 Y,98个牛顿