"Bill" <> wrote in message
news:...
> No, that's not what I mean. I know how to get the names off the
> submitted form. What I don't understand is how to grab the value of
> checked or not checked.
>
> For example,
>
> if checkbox1=checked then
> do this
> else
> do that
> end if
>
> This should work, but the opposite is happening. The above code will
> process those that are not checked, and ignore those that are, so I
> can't figure out how to assigned the checked value to the name. If
it's
> checked, do I write checked, or selected, or what?
[CategoryBooksForm.asp]
..
..
..
<input type="Hidden" name="CategoryID" value="222">
<input type="Checkbox" name="BookIDs" value="101">Name of book whose ID
is 101<br>
<input type="Checkbox" name="BookIDs" value="102">Name of book whose ID
is 102<br>
<input type="Checkbox" name="BookIDs" value="103">Name of book whose ID
is 103<br>
<input type="Checkbox" name="BookIDs" value="104">Name of book whose ID
is 104<br>
..
..
..
[CategoryBooksInsert.asp]
..
..
..
sql = _
"INSERT INTO CategoryBook (CategoryID,BookID)" & vbCRLF &_
"SELECT " & Request.Form("CategoryID") & " AS CategoryID, BookID" &
vbCRLF &_
"FROM Book" & vbCRLF &_
"WHERE BookID IN (" & Request.Form("BookIDs") & ")"
Set cn = CreateObject("ADODB.Connection")
cn.Open "File Name = C:\SomePathOutsideAppRoot\MyConnection.UDL"
cn.Execute sql,,&H81
..
..
..
Notes:
1. In future posts, please provide database, version and table structure
information as this will often result in a responses crafted to suit
your particular environment.
2. When something is not working as expected, please post code. Just
enough to allow readers/responders to understand your methodology and
reproduce the behavior.
3. When dealing with databases, if a query is not behaving as expected,
Response.Write the SQL statement and cut and paste the generated text
into the Access Query Design Grid/SQL Server Query Analyzer. These query
building environments provide a richer feature set than ASP for
analyzing/debugging SQL statements.
4. The above is obviously not code-complete. Please make sure you
perform due diligence. Close/destroy all objects, validate parameters,
include error handling, etc...
5. Once the above code is working, please consider encapsulating the
insertion logic into a parameterized query/stored procedure. If the
database supports full-fledged stored procedures (SQL Server, Oracle,
MySQL 5.0, etc...) then you should also consider implementing a
set-based solution to passing an array of values into stored procedures.
Here's a link with more information on that topic.
http://www.algonet.se/~sommar/arrays-in-sql.html
HTH
-Chris