473,509 Members | 2,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checkbox Array

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?
Jul 19 '05 #1
4 8184
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" <WC*****@bellsouth.net> wrote in message
news:j%***************@bignews1.bellsouth.net...
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?

Jul 19 '05 #2
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" <da***@davidmorgan.me.uk> wrote in message
news:uD**************@TK2MSFTNGP09.phx.gbl...
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" <WC*****@bellsouth.net> wrote in message
news:j%***************@bignews1.bellsouth.net...
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?


Jul 19 '05 #3
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" <da***@davidmorgan.me.uk> wrote in message
news:uD**************@TK2MSFTNGP09.phx.gbl...
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" <WC*****@bellsouth.net> wrote in message
news:j%***************@bignews1.bellsouth.net...
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?


Jul 19 '05 #4
Sounds good.
"WC Justice" <WC*****@bellsouth.net> wrote in message
news:10*************@corp.supernews.com...
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" <da***@davidmorgan.me.uk> wrote in message
news:uD**************@TK2MSFTNGP09.phx.gbl...
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" <WC*****@bellsouth.net> wrote in message
news:j%***************@bignews1.bellsouth.net...
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?



Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1988
by: Steve | last post by:
I'm working on a page for an e-commerce site that has a form than lists items in an order placed by a customer. The form serves two purposes: to edit and save the details of the items (i.e. number...
2
6628
by: Paul Morrison | last post by:
Hi, I am new to Javascript and am having a bit of difficulty. On my site, in order for a member to unsubscribe from an article, they go to the'Unsubscribe' page where they get a table of all of...
4
3866
by: Paul Morrison | last post by:
Hi, I have a checkbox array containing the id of a record in a MySQL database. The checkboxes are created dynamically depending on what is stored in the database. I want to send the checkbox...
3
8545
by: aparth | last post by:
Hi, I'm having a problem simply putting the values of selected checkboxes into an array using javascript. The list of checkboxes is dynamically created so I need to count number of checkboxes in...
3
3610
by: JackM | last post by:
Okay, I'm starting to get a little ticked off because I've worked for hours on this and I can't seem to find the cause. I'm using PHP 5.1.6. I'm trying to get the values of some form checkboxes...
0
1632
by: Nolanclark | last post by:
Hi there. I've read a previous thread regarding the Old VB 6 checkbox array and how it's not really needed any more. That's fine, but I'm not really sure how to implement the checkbox control array...
3
5294
realin
by: realin | last post by:
Hiya all, i am in deep trouble, i thought it was an easy task, but now its getting on my nerves. Well i have a div on a form, which contains a number of checkboxes, as <div...
4
2150
by: Joni Seth | last post by:
I have a database of required skills for employees. There is a many to many relationship between the users table and the skills table, called user_skills. It contains the following fields: auto...
1
2597
by: Greg Eyres | last post by:
Apologies if this is a stupid question ... I'm new to this PHP world! I have got an html form that has checkboxes dynamically created from MySQL. I use an array to create the list of checkboxes. ...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.