Using Checkbox for assigning items

Discussion in 'ASP General' started by Chris Hohmann, Sep 2, 2003.

  1. "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
     
    Chris Hohmann, Sep 2, 2003
    #1
    1. Advertising

  2. Chris Hohmann

    Bill Guest

    I have a catalog of books which need to be categorized into different
    groups. Some of the books can be listed under more than one category.
    I'm creating a page where I can assign a group of books to a category
    by checking the checkbox next to their name (say I've looped out 100
    of them, and check some, and not others) then submitting the form for
    processing, so that those titles where the checkbox is checked will
    get the categoryid number assigned to them on a one-to-many table

    I need to know how to read the checkbox value as it comes in if it is
    selected or not, if it is, I'll send the isbn in one direction, and if
    not, I won't send it at all.

    So, how would I read this on the sheet that grabs the values?

    Thanks,

    Bill
     
    Bill, Sep 2, 2003
    #2
    1. Advertising

  3. Chris Hohmann

    Curt_C [MVP] Guest

    Request.Form("chkBoxName")

    Is that what you mean?

    --
    ----------------------------------------------------------
    Curt Christianson (Software_AT_Darkfalz.Com)
    Owner/Lead Designer, DF-Software
    http://www.Darkfalz.com
    ---------------------------------------------------------
    ...Offering free scripts & code snippits for everyone...
    ---------------------------------------------------------


    "Bill" <> wrote in message
    news:...
    > I have a catalog of books which need to be categorized into different
    > groups. Some of the books can be listed under more than one category.
    > I'm creating a page where I can assign a group of books to a category
    > by checking the checkbox next to their name (say I've looped out 100
    > of them, and check some, and not others) then submitting the form for
    > processing, so that those titles where the checkbox is checked will
    > get the categoryid number assigned to them on a one-to-many table
    >
    > I need to know how to read the checkbox value as it comes in if it is
    > selected or not, if it is, I'll send the isbn in one direction, and if
    > not, I won't send it at all.
    >
    > So, how would I read this on the sheet that grabs the values?
    >
    > Thanks,
    >
    > Bill
     
    Curt_C [MVP], Sep 3, 2003
    #3
  4. Chris Hohmann

    Bill Guest

    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?

    Thanks,

    Bill

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Bill, Sep 3, 2003
    #4
  5. I face this issue quite a lot. My solution is to accompany each checkbox
    with a hidden control, both similarly named, as in:

    <input type="checkbox" name="chkBookNumber1"> Book Title
    <input type="hidden" name="hidBookNumber1" value="(checked=1, not
    checked=0)">

    When the form is submitted, I compare the two.
    If the hidden control is 1 and the checkbox is "empty": it was selected,
    now it's not
    If the hidden control is 1 and the checkbox is 1: nothing's changed
    If the hidden control is 0 and the checkbox is "empty": it was not
    selected, nothing's changed
    If the hidden control is 0 and the checkbox is 1: it wasn't selected,
    now it is

    Takes a bit of processing, but it's worth it.


    --
    William Morris
    Product Development, Seritas LLC


    "Bill" <> wrote in message
    news:...
    > I have a catalog of books which need to be categorized into different
    > groups. Some of the books can be listed under more than one category.
    > I'm creating a page where I can assign a group of books to a category
    > by checking the checkbox next to their name (say I've looped out 100
    > of them, and check some, and not others) then submitting the form for
    > processing, so that those titles where the checkbox is checked will
    > get the categoryid number assigned to them on a one-to-many table
    >
    > I need to know how to read the checkbox value as it comes in if it is
    > selected or not, if it is, I'll send the isbn in one direction, and if
    > not, I won't send it at all.
    >
    > So, how would I read this on the sheet that grabs the values?
    >
    > Thanks,
    >
    > Bill
     
    WIlliam Morris, Sep 3, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gilles Kuhn
    Replies:
    0
    Views:
    456
    Gilles Kuhn
    Sep 15, 2003
  2. Bart Van Hemelen
    Replies:
    2
    Views:
    4,720
    Bart Van Hemelen
    Sep 4, 2006
  3. Larry Bud
    Replies:
    13
    Views:
    7,815
    Larry Bud
    Jan 7, 2008
  4. Ben
    Replies:
    2
    Views:
    961
  5. weston
    Replies:
    1
    Views:
    280
    Richard Cornford
    Sep 22, 2006
Loading...

Share This Page