Working with Multiple Checkboxes
Written by Eric Smith, Northstar Computer Systems LLC
In an application I'm writing, I have a form that shows a large number of checkboxes to the user. These checkboxes each become a record in a database table related to the primary entity. In order to make it easy to insert the appropriate records for the main record, I created a naming structure for each box based on it primary key of the value shown by the checkbox. Prefixing the name with "dbchk" makes it easier to find when looping through the Request collection. Once I determine if the box was checked, I call a stored procedure to insert the record into the table. Here's an example of how to check the value, assuming the name is dbchkValue##, which ## being the number of the category.
Dim item ' As Variant
For Each item in Request.Form
If Left(item.Name, 5) = "dbchk" Then
If Request(item.Value) = "Y" Then
dcnDB.Execute("sp_AddRecordToTable " & Mid(item.Name, 11))
End If
End If
Next ' item
This will automatically insert a row into the table for each check box that is marked. It also saves you from having to write lots of redundant code to insert particular rows into the table.
Keywords: [
Uncategorized ASP Tips
]
Publication Date: 5/1/2000
|