Connecting Tech Pros Worldwide Forums | Help | Site Map

Checkbox Array

WC Justice
Guest
 
Posts: n/a
#1: Jul 19 '05
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
Guest
 
Posts: n/a
#2: Jul 19 '05

re: Checkbox Array


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" <WCJEInc@bellsouth.net> wrote in message
news:j%aQc.836$zJ4.247@bignews1.bellsouth.net...[color=blue]
> 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[/color]
to[color=blue]
> 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?
>
>[/color]


David Morgan
Guest
 
Posts: n/a
#3: Jul 19 '05

re: Checkbox Array


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" <david@davidmorgan.me.uk> wrote in message
news:uDqa0gmeEHA.1356@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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" <WCJEInc@bellsouth.net> wrote in message
> news:j%aQc.836$zJ4.247@bignews1.bellsouth.net...[color=green]
> > I have an ASP form that uses a recordset to build a table, with one of[/color][/color]
the[color=blue][color=green]
> > columns containing a checkbox. Upon posting, the ASP code of the[/color][/color]
Post-To[color=blue][color=green]
> > page uses the "For i = 1 to request.form("chkAddToInvoice").count"[/color][/color]
method[color=blue]
> to[color=green]
> > go through the array, but it only counts checked boxes. Not only is[/color][/color]
this[color=blue][color=green]
> > causing the corresponding Update statement to write values to the wrong
> > records, it is preventing me from using the "False" value of the check[/color][/color]
box[color=blue][color=green]
> > to run its corresponding Update statement.
> >
> > Is there a way to set up the checkbox so that it is counted whether it[/color][/color]
is[color=blue][color=green]
> > selected or not?
> >
> >[/color]
>
>[/color]


WC Justice
Guest
 
Posts: n/a
#4: Jul 19 '05

re: Checkbox Array


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" <david@davidmorgan.me.uk> wrote in message
news:uDqa0gmeEHA.1356@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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" <WCJEInc@bellsouth.net> wrote in message
> news:j%aQc.836$zJ4.247@bignews1.bellsouth.net...[color=green]
> > I have an ASP form that uses a recordset to build a table, with one of[/color][/color]
the[color=blue][color=green]
> > columns containing a checkbox. Upon posting, the ASP code of the[/color][/color]
Post-To[color=blue][color=green]
> > page uses the "For i = 1 to request.form("chkAddToInvoice").count"[/color][/color]
method[color=blue]
> to[color=green]
> > go through the array, but it only counts checked boxes. Not only is[/color][/color]
this[color=blue][color=green]
> > causing the corresponding Update statement to write values to the wrong
> > records, it is preventing me from using the "False" value of the check[/color][/color]
box[color=blue][color=green]
> > to run its corresponding Update statement.
> >
> > Is there a way to set up the checkbox so that it is counted whether it[/color][/color]
is[color=blue][color=green]
> > selected or not?
> >
> >[/color]
>
>[/color]


David Morgan
Guest
 
Posts: n/a
#5: Jul 19 '05

re: Checkbox Array


Sounds good.


"WC Justice" <WCJEInc@bellsouth.net> wrote in message
news:10h2luer1ob3m68@corp.supernews.com...[color=blue]
> Thanks for the quick reply.
>
> I'm thinking that I could add a hidden box to each row with a value of 0[/color]
or[color=blue]
> 1 and that can be updated with the onChange event in javascript. That way[/color]
I[color=blue]
> will still have the user-friendly checkbox and all records would have a
> corresponding value to be counted and used to direct subsequent code.[/color]
Does[color=blue]
> that sound like it might work?
>
> "David Morgan" <david@davidmorgan.me.uk> wrote in message
> news:uDqa0gmeEHA.1356@TK2MSFTNGP09.phx.gbl...[color=green]
> > 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[/color][/color]
Then[color=blue][color=green]
> > ' 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[/color][/color]
can[color=blue][color=green]
> > change the value field to anything then.
> >
> > Regards
> >
> > David
> >
> >
> > "WC Justice" <WCJEInc@bellsouth.net> wrote in message
> > news:j%aQc.836$zJ4.247@bignews1.bellsouth.net...[color=darkred]
> > > I have an ASP form that uses a recordset to build a table, with one of[/color][/color]
> the[color=green][color=darkred]
> > > columns containing a checkbox. Upon posting, the ASP code of the[/color][/color]
> Post-To[color=green][color=darkred]
> > > page uses the "For i = 1 to request.form("chkAddToInvoice").count"[/color][/color]
> method[color=green]
> > to[color=darkred]
> > > go through the array, but it only counts checked boxes. Not only is[/color][/color]
> this[color=green][color=darkred]
> > > causing the corresponding Update statement to write values to the[/color][/color][/color]
wrong[color=blue][color=green][color=darkred]
> > > records, it is preventing me from using the "False" value of the check[/color][/color]
> box[color=green][color=darkred]
> > > to run its corresponding Update statement.
> > >
> > > Is there a way to set up the checkbox so that it is counted whether it[/color][/color]
> is[color=green][color=darkred]
> > > selected or not?
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread