how to implement a check box in classic asp

与世无争的帅哥 提交于 2019-12-25 14:00:48

问题


I have a checkbox

<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>

How do i capture whether the checkbox is checked or unchecked when form is submitted?

OnlineOrdering = request.form("OnlineOrdering")

this does not work?


回答1:


This should assign a true/false to the variable OnlineOrdering:

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



回答2:


I found this post because I was trying to solve the same problem. I have a solution that seems to work well.

In the HTML form, create dynamically generated checkboxes. The value of this_box_id used below can be any unique number. In my case it was the primary key (autonumber) for that question from the SQL Database . Dynamically generated the check boxes with an associated hidden field:

<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%>">

When asp returns the values for this, it will return multiple values for check_box_indicator. Here's a sample query string snippet:

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

On the next page, ASP will read through the form data. It will find EVERY check_box_indicator and it's value. That value can be used to check the value of the associated checkbox. If that checkbox comes back, it was checked, if it doesn't you will know that it wasn't checked. In the sample above, checkbox 78 was checked and so the box_id78 value was passed, while checkbox 98 was not and box_id98 was not sent. Here's the code to use this.

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

With the example querystring, you will get 78 y, 98 n



来源:https://stackoverflow.com/questions/8759663/how-to-implement-a-check-box-in-classic-asp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!