Checkbox Array

Discussion in 'ASP General' started by WC Justice, Aug 4, 2004.

  1. WC Justice

    WC Justice Guest

    I have an ASP form that uses a recordset to build a table, with one of the
    columns containing a checkbox. Upon posting, the ASP code of the Post-To
    page uses the "For i = 1 to request.form("chkAddToInvoice").count" method to
    go through the array, but it only counts checked boxes. Not only is this
    causing the corresponding Update statement to write values to the wrong
    records, it is preventing me from using the "False" value of the check box
    to run its corresponding Update statement.

    Is there a way to set up the checkbox so that it is counted whether it is
    selected or not?
     
    WC Justice, Aug 4, 2004
    #1
    1. Advertising

  2. WC Justice

    David Morgan Guest

    No.

    With radios, check boxes and buttons, only the values of selected, (or
    clicked), elements are submitted.

    You could re-run the query in the "post-to" page and loop through the
    recordset saying

    If (Request.Form("cbxAddToInvoice_" & objRs.Fields("ID").Value).Count Then
    ' Update to true
    Else
    ' Update to false
    End If

    Note you would need to change the name of the checkboxes on the original
    page to incorporate the ID of the record the checkbox represents. You
    probably have this in the checkboxes' value field at the moment. You can
    change the value field to anything then.

    Regards

    David


    "WC Justice" <> wrote in message
    news:j%aQc.836$...
    > I have an ASP form that uses a recordset to build a table, with one of the
    > columns containing a checkbox. Upon posting, the ASP code of the Post-To
    > page uses the "For i = 1 to request.form("chkAddToInvoice").count" method

    to
    > go through the array, but it only counts checked boxes. Not only is this
    > causing the corresponding Update statement to write values to the wrong
    > records, it is preventing me from using the "False" value of the check box
    > to run its corresponding Update statement.
    >
    > Is there a way to set up the checkbox so that it is counted whether it is
    > selected or not?
    >
    >
     
    David Morgan, Aug 4, 2004
    #2
    1. Advertising

  3. WC Justice

    David Morgan Guest

    Actually, that could be a bit dangerous if people add to the record set
    while the person is checking the boxes.

    A better approach would be to GetRows the recordset in to an array and
    create a hidden field that contains all the IDs.

    <%
    Set objRs = objConn.Execute("STATEMENT", , adCmdText)
    If Not objRs.EOF Then
    bHasResults = True
    arrResults = objRs.GetRows
    iResults = UBound(arrResults, 2)
    End If %>

    <form ...>
    <% For i = 0 To iResults %>
    <input type=checkbox name="chkInvoiceID_<%=arrResults(0, i)%>" value=ON>
    <% Next%>
    <input type="hidden" name="AllIDs" value="<% For i = 0 To iResults:
    Response.Write arrResults(0, i) & ",": Next%>"
    </form>


    Then in the post to page do

    stAllIDs = Request.Form("AllIDs")
    If Len(stAllIDs) > 0 Then
    arrAllIDs = Split(stAllIDs, ",")
    End If

    And then proceed as before using arrAllIDs(i) instead of the record set ID
    field.

    Gotta dash...

    "David Morgan" <> wrote in message
    news:...
    > No.
    >
    > With radios, check boxes and buttons, only the values of selected, (or
    > clicked), elements are submitted.
    >
    > You could re-run the query in the "post-to" page and loop through the
    > recordset saying
    >
    > If (Request.Form("cbxAddToInvoice_" & objRs.Fields("ID").Value).Count Then
    > ' Update to true
    > Else
    > ' Update to false
    > End If
    >
    > Note you would need to change the name of the checkboxes on the original
    > page to incorporate the ID of the record the checkbox represents. You
    > probably have this in the checkboxes' value field at the moment. You can
    > change the value field to anything then.
    >
    > Regards
    >
    > David
    >
    >
    > "WC Justice" <> wrote in message
    > news:j%aQc.836$...
    > > I have an ASP form that uses a recordset to build a table, with one of

    the
    > > columns containing a checkbox. Upon posting, the ASP code of the

    Post-To
    > > page uses the "For i = 1 to request.form("chkAddToInvoice").count"

    method
    > to
    > > go through the array, but it only counts checked boxes. Not only is

    this
    > > causing the corresponding Update statement to write values to the wrong
    > > records, it is preventing me from using the "False" value of the check

    box
    > > to run its corresponding Update statement.
    > >
    > > Is there a way to set up the checkbox so that it is counted whether it

    is
    > > selected or not?
    > >
    > >

    >
    >
     
    David Morgan, Aug 4, 2004
    #3
  4. WC Justice

    David Morgan Guest

    Sounds good.


    "WC Justice" <> wrote in message
    news:...
    > Thanks for the quick reply.
    >
    > I'm thinking that I could add a hidden box to each row with a value of 0

    or
    > 1 and that can be updated with the onChange event in javascript. That way

    I
    > will still have the user-friendly checkbox and all records would have a
    > corresponding value to be counted and used to direct subsequent code.

    Does
    > that sound like it might work?
    >
    > "David Morgan" <> wrote in message
    > news:...
    > > No.
    > >
    > > With radios, check boxes and buttons, only the values of selected, (or
    > > clicked), elements are submitted.
    > >
    > > You could re-run the query in the "post-to" page and loop through the
    > > recordset saying
    > >
    > > If (Request.Form("cbxAddToInvoice_" & objRs.Fields("ID").Value).Count

    Then
    > > ' Update to true
    > > Else
    > > ' Update to false
    > > End If
    > >
    > > Note you would need to change the name of the checkboxes on the original
    > > page to incorporate the ID of the record the checkbox represents. You
    > > probably have this in the checkboxes' value field at the moment. You

    can
    > > change the value field to anything then.
    > >
    > > Regards
    > >
    > > David
    > >
    > >
    > > "WC Justice" <> wrote in message
    > > news:j%aQc.836$...
    > > > I have an ASP form that uses a recordset to build a table, with one of

    > the
    > > > columns containing a checkbox. Upon posting, the ASP code of the

    > Post-To
    > > > page uses the "For i = 1 to request.form("chkAddToInvoice").count"

    > method
    > > to
    > > > go through the array, but it only counts checked boxes. Not only is

    > this
    > > > causing the corresponding Update statement to write values to the

    wrong
    > > > records, it is preventing me from using the "False" value of the check

    > box
    > > > to run its corresponding Update statement.
    > > >
    > > > Is there a way to set up the checkbox so that it is counted whether it

    > is
    > > > selected or not?
    > > >
    > > >

    > >
    > >

    >
    >
     
    David Morgan, Aug 4, 2004
    #4
    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. tshad
    Replies:
    0
    Views:
    565
    tshad
    Apr 15, 2005
  2. Vikram

    disable checkbox list checkbox

    Vikram, Jan 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,423
    ThunderMusic
    Jan 25, 2006
  3. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    858
    David Wier
    Oct 6, 2006
  4. Jason Huang
    Replies:
    0
    Views:
    580
    Jason Huang
    Jun 29, 2007
  5. Joey Pang
    Replies:
    4
    Views:
    549
    Joey Pang
    Jun 13, 2005
Loading...

Share This Page