473,783 Members | 2,317 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic checkboxes

I have a page which has something like 100 checkboxes, in three categories,
so I chose to build the checkboxes into the page like this:

<%
strSQL = "SELECT PeopleID, PeopleDesc "
strSQL = strSQL & "FROM People "
strSQL = strSQL & "ORDER BY PeopleDesc"
set rs = conn.execute(st rSQL)

strTempRow = 0
While Not RS.EOF
Response.Write "<td colspan=2><inpu t type=checkbox
value='"&RS.Fie lds("PeopleID") &"'>"&RS.Fields ("PeopleDesc")& "</td>"
strTempRow = strTempRow + 1
If strTempRow mod 2 = 0 then
response.write "</tr><tr>"
Else
End if
RS.MoveNext
WEND
RS.Close
set RS = nothing

%>
As you can see, I don't have a name for the checkbox, but of course, I need
to have that, so that on the next page, I can retrieve the value and insert
it into a database, if it was selected.

How is this handled on this page? How is it handled on the next page? I am
at a loss to figure this out.
Jul 19 '05 #1
6 4488
Response.Write "<td colspan=2><inpu t type=checkbox
name = 'chkSomething" & strTempRow & "'
value='"&RS.Fie lds("PeopleID") &"'>"&RS.Fields ("PeopleDesc")& "</td>"
strTempRow = strTempRow + 1
--
Roji. P. Thomas
SQL Server Programmer
--------------------------------------
"middletree " <mi********@hto mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
I have a page which has something like 100 checkboxes, in three categories, so I chose to build the checkboxes into the page like this:

<%
strSQL = "SELECT PeopleID, PeopleDesc "
strSQL = strSQL & "FROM People "
strSQL = strSQL & "ORDER BY PeopleDesc"
set rs = conn.execute(st rSQL)

strTempRow = 0
While Not RS.EOF
Response.Write "<td colspan=2><inpu t type=checkbox
value='"&RS.Fie lds("PeopleID") &"'>"&RS.Fields ("PeopleDesc")& "</td>"
strTempRow = strTempRow + 1
If strTempRow mod 2 = 0 then
response.write "</tr><tr>"
Else
End if
RS.MoveNext
WEND
RS.Close
set RS = nothing

%>
As you can see, I don't have a name for the checkbox, but of course, I need to have that, so that on the next page, I can retrieve the value and insert it into a database, if it was selected.

How is this handled on this page? How is it handled on the next page? I am at a loss to figure this out.

Jul 19 '05 #2
I do one of two things.

1) <input type=checkbox name=Person<%=t rim(RS.Fields(" PeopleID"))%>>
which gives <input type=checkbox name=Person1>
then on the following page, I requery and check each value

2) <input type=checkbox name=Person value="<%=RS.Fi elds("PeopleID" )%>">
which gives <input type=checkbox name=Person value="1">
then on the following page, I Request.Form("P erson") which gives me a comma
separated string of the selected values. So if 1, 6 and 8 were picked I'd
get "1, 6, 8" which is easily popped into an array using SPLIT.
I can also use that handy dandy little string in my SQL Statement,
sPerson=Request .Form("Person")
sSQL="UPDATE People SET Deleted=1 WHERE PeopleID in ('" & sPerson & "')"
sSQL="UPDATE People SET Deleted=0 WHERE PeopleID not in ('" & sPerson &
"')"

I prefer to use method 2, but there are times when the 1st method is easier.
"middletree " <mi********@hto mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
I have a page which has something like 100 checkboxes, in three categories, so I chose to build the checkboxes into the page like this:

<%
strSQL = "SELECT PeopleID, PeopleDesc "
strSQL = strSQL & "FROM People "
strSQL = strSQL & "ORDER BY PeopleDesc"
set rs = conn.execute(st rSQL)

strTempRow = 0
While Not RS.EOF
Response.Write "<td colspan=2><inpu t type=checkbox
value='"&RS.Fie lds("PeopleID") &"'>"&RS.Fields ("PeopleDesc")& "</td>"
strTempRow = strTempRow + 1
If strTempRow mod 2 = 0 then
response.write "</tr><tr>"
Else
End if
RS.MoveNext
WEND
RS.Close
set RS = nothing

%>
As you can see, I don't have a name for the checkbox, but of course, I need to have that, so that on the next page, I can retrieve the value and insert it into a database, if it was selected.

How is this handled on this page? How is it handled on the next page? I am at a loss to figure this out.

Jul 19 '05 #3
Huh? I don't understand. How does this give each checkbox a unique name?

And how do I capture it on the next page?
"Roji. P. Thomas" <la********@som ewhere.com> wrote in message
news:Oq******** ******@TK2MSFTN GP11.phx.gbl...
Response.Write "<td colspan=2><inpu t type=checkbox
name = 'chkSomething" & strTempRow & "'
value='"&RS.Fie lds("PeopleID") &"'>"&RS.Fields ("PeopleDesc")& "</td>"
strTempRow = strTempRow + 1
--
Roji. P. Thomas
SQL Server Programmer
--------------------------------------
"middletree " <mi********@hto mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
I have a page which has something like 100 checkboxes, in three

categories,
so I chose to build the checkboxes into the page like this:

<%
strSQL = "SELECT PeopleID, PeopleDesc "
strSQL = strSQL & "FROM People "
strSQL = strSQL & "ORDER BY PeopleDesc"
set rs = conn.execute(st rSQL)

strTempRow = 0
While Not RS.EOF
Response.Write "<td colspan=2><inpu t type=checkbox
value='"&RS.Fie lds("PeopleID") &"'>"&RS.Fields ("PeopleDesc")& "</td>"
strTempRow = strTempRow + 1
If strTempRow mod 2 = 0 then
response.write "</tr><tr>"
Else
End if
RS.MoveNext
WEND
RS.Close
set RS = nothing

%>
As you can see, I don't have a name for the checkbox, but of course, I

need
to have that, so that on the next page, I can retrieve the value and

insert
it into a database, if it was selected.

How is this handled on this page? How is it handled on the next page? I

am
at a loss to figure this out.


Jul 19 '05 #4
Ok, this looks like something I can use. Just help me understand a little
bit more, though. I got everything you said through "1,6,8", but then I got
lost. Not sure how arrays work, have tried to work with them before, but
wasn't successful. But I could use your SQL method which you have
afterward, but I don't understand the deleted part.

Just so I'm clear, the People table is one table, and it will be pretty
static. The values from this page will be stored in a composite table, which
will have the individual's ID from the Personal table, and then the PeopleID
from the People table (People refers to which people group would you like to
work with: children, prisoners, elderly, etc.)--go to
www.middeltree.net/shape.htm for an html version of this page I'm working on

So I'd want to store some other info which is typed by the user, into the
Personal table, then store the checkbox stuff into the composite table.

Having said that, I appreciate what you have shown me about how you can give
all those checkboxes the same name and a comma-delimited string will come
out, just now sure how I can request that, split it, and insert it on the
next page.
"TomB" <sh*****@hotmai l.com> wrote in message
news:#b******** ******@tk2msftn gp13.phx.gbl...
2) <input type=checkbox name=Person value="<%=RS.Fi elds("PeopleID" )%>">
which gives <input type=checkbox name=Person value="1">
then on the following page, I Request.Form("P erson") which gives me a comma separated string of the selected values. So if 1, 6 and 8 were picked I'd
get "1, 6, 8" which is easily popped into an array using SPLIT.
I can also use that handy dandy little string in my SQL Statement,
sPerson=Request .Form("Person")
sSQL="UPDATE People SET Deleted=1 WHERE PeopleID in ('" & sPerson & "')"
sSQL="UPDATE People SET Deleted=0 WHERE PeopleID not in ('" & sPerson &
"')"

Jul 19 '05 #5
Ok, first off I'd expect you to spell middletree correctly ;)

1) the reason for the DELETE was that I didn't know what you were using it
for. I have an administrative page where the administrator adds or removes
staff. Rather than actually delete the record, I just have a field called
Deleted which is normally set to 0 (false) and when the staff is deleted it
is set to 1 (true). Using my method, it would set all of the "selected"
staff to 1 and the unselected to 0. Yours doesn't appear to need that, as
you are doing an INSERT (right?) So for your situation you could split it
into an array like so.......

' I'm going to assume that 3=Young Married, 6=College and 7=Homosexual
' and that these are the choices selected

sPeopleGroups=R equest.Form("Pe opleGroups")
arrPeopleGroups =SPLIT(sPeopleG roups,",")

'At this point I have an array with three elements
'arrPeopleGroup s(0)=3
'arrPeopleGroup s(1)=6
'arrPeopleGroup s(2)=7
'So you could use the array to create a loop of Insert statements

For iLoop = 0 to UBound(arrPeopl eGroups)
sSQL="INSERT INTO tblPeopleGroups Selected (parentID, selectedID)
VALUES(" & lngIdentity & ", " & arrPeopleGroups (iLoop) & ")"
connectionObjec t.Execute sSQL
Next

'The above would create and execute three sql statements. I've assumed that
lngIdentity was created earlier in the page, to represent the parent tables
identity value.
For what you are doing though, I don't think you need an array. Assuming
that the values (Young Married, etc.) are coming from a table (let's say
tblPeopleGroups ) then you can use
INSERT INTO tblPeopleGroups Selected (parentID, selectedID) SELECT 999,
peopleGroupID FROM tblPeopleGroups WHERE peopleGroupID in (3, 6, 7)

Where 999 is the Identity value from the parent table.

OK. I've just reread your post. My tblPeopleGroups Selected would be what
you referred to as "composite table." I would have that as a one-to-many
table (one Person - many Groups) which would consist of two fields as the Pr
imaryKey. PeopleID and GroupID - where PeopleID is a foreign key linked to
your People table and GroupID is a foreign key linked to your
tblPeopleGroups table.

So if I was number 4 and I wanted to be hooked up with 3,6 and 7 then the
table would look like.....
PeopleID GroupID
4 3
4 6
4 7

I think that'd do what you need.

TOm B

"middletree " <mi********@hto mail.com> wrote in message
news:O5******** ********@TK2MSF TNGP12.phx.gbl. ..
Ok, this looks like something I can use. Just help me understand a little
bit more, though. I got everything you said through "1,6,8", but then I got lost. Not sure how arrays work, have tried to work with them before, but
wasn't successful. But I could use your SQL method which you have
afterward, but I don't understand the deleted part.

Just so I'm clear, the People table is one table, and it will be pretty
static. The values from this page will be stored in a composite table, which will have the individual's ID from the Personal table, and then the PeopleID from the People table (People refers to which people group would you like to work with: children, prisoners, elderly, etc.)--go to
www.middeltree.net/shape.htm for an html version of this page I'm working on
So I'd want to store some other info which is typed by the user, into the
Personal table, then store the checkbox stuff into the composite table.

Having said that, I appreciate what you have shown me about how you can give all those checkboxes the same name and a comma-delimited string will come
out, just now sure how I can request that, split it, and insert it on the
next page.
"TomB" <sh*****@hotmai l.com> wrote in message
news:#b******** ******@tk2msftn gp13.phx.gbl...
2) <input type=checkbox name=Person value="<%=RS.Fi elds("PeopleID" )%>"> which gives <input type=checkbox name=Person value="1">
then on the following page, I Request.Form("P erson") which gives me a

comma
separated string of the selected values. So if 1, 6 and 8 were picked I'd get "1, 6, 8" which is easily popped into an array using SPLIT.
I can also use that handy dandy little string in my SQL Statement,
sPerson=Request .Form("Person")
sSQL="UPDATE People SET Deleted=1 WHERE PeopleID in ('" & sPerson & "')"
sSQL="UPDATE People SET Deleted=0 WHERE PeopleID not in ('" & sPerson &
"')"


Jul 19 '05 #6
First off, I can't believe I mispelled my own domain name. Wait, yes I can.

As an aside, if I would have known that the random numbers I chose in my
first post included the homosexual one, I would have chosen a different one,
as I don't want to do anything here that is even slightly volitile.
Volatile. Whatever.

Having said that, I looked at your code, and I think it will work for what I
need. I appreciate your help and I'll try it out tonight when I get home.

thanks
"TomB" <sh*****@hotmai lXXX.com> wrote in message
news:#k******** ******@TK2MSFTN GP10.phx.gbl...
Ok, first off I'd expect you to spell middletree correctly ;)

1) the reason for the DELETE was that I didn't know what you were using it
for. I have an administrative page where the administrator adds or removes staff. Rather than actually delete the record, I just have a field called
Deleted which is normally set to 0 (false) and when the staff is deleted it is set to 1 (true). Using my method, it would set all of the "selected"
staff to 1 and the unselected to 0. Yours doesn't appear to need that, as
you are doing an INSERT (right?) So for your situation you could split it
into an array like so.......

' I'm going to assume that 3=Young Married, 6=College and 7=Homosexual
' and that these are the choices selected

sPeopleGroups=R equest.Form("Pe opleGroups")
arrPeopleGroups =SPLIT(sPeopleG roups,",")

'At this point I have an array with three elements
'arrPeopleGroup s(0)=3
'arrPeopleGroup s(1)=6
'arrPeopleGroup s(2)=7
'So you could use the array to create a loop of Insert statements

For iLoop = 0 to UBound(arrPeopl eGroups)
sSQL="INSERT INTO tblPeopleGroups Selected (parentID, selectedID)
VALUES(" & lngIdentity & ", " & arrPeopleGroups (iLoop) & ")"
connectionObjec t.Execute sSQL
Next

'The above would create and execute three sql statements. I've assumed that lngIdentity was created earlier in the page, to represent the parent tables identity value.
For what you are doing though, I don't think you need an array. Assuming
that the values (Young Married, etc.) are coming from a table (let's say
tblPeopleGroups ) then you can use
INSERT INTO tblPeopleGroups Selected (parentID, selectedID) SELECT 999,
peopleGroupID FROM tblPeopleGroups WHERE peopleGroupID in (3, 6, 7)

Where 999 is the Identity value from the parent table.

OK. I've just reread your post. My tblPeopleGroups Selected would be what
you referred to as "composite table." I would have that as a one-to-many
table (one Person - many Groups) which would consist of two fields as the Pr imaryKey. PeopleID and GroupID - where PeopleID is a foreign key linked to your People table and GroupID is a foreign key linked to your
tblPeopleGroups table.

So if I was number 4 and I wanted to be hooked up with 3,6 and 7 then the
table would look like.....
PeopleID GroupID
4 3
4 6
4 7

I think that'd do what you need.

TOm B

"middletree " <mi********@hto mail.com> wrote in message
news:O5******** ********@TK2MSF TNGP12.phx.gbl. ..
Ok, this looks like something I can use. Just help me understand a little
bit more, though. I got everything you said through "1,6,8", but then I got
lost. Not sure how arrays work, have tried to work with them before, but wasn't successful. But I could use your SQL method which you have
afterward, but I don't understand the deleted part.

Just so I'm clear, the People table is one table, and it will be pretty
static. The values from this page will be stored in a composite table,

which
will have the individual's ID from the Personal table, and then the

PeopleID
from the People table (People refers to which people group would you like to
work with: children, prisoners, elderly, etc.)--go to
www.middeltree.net/shape.htm for an html version of this page I'm
working on

So I'd want to store some other info which is typed by the user, into

the Personal table, then store the checkbox stuff into the composite table.

Having said that, I appreciate what you have shown me about how you can

give
all those checkboxes the same name and a comma-delimited string will come out, just now sure how I can request that, split it, and insert it on the next page.
"TomB" <sh*****@hotmai l.com> wrote in message
news:#b******** ******@tk2msftn gp13.phx.gbl...
2) <input type=checkbox name=Person

value="<%=RS.Fi elds("PeopleID" )%>"> which gives <input type=checkbox name=Person value="1">
then on the following page, I Request.Form("P erson") which gives me a

comma
separated string of the selected values. So if 1, 6 and 8 were picked I'd get "1, 6, 8" which is easily popped into an array using SPLIT.
I can also use that handy dandy little string in my SQL Statement,
sPerson=Request .Form("Person")
sSQL="UPDATE People SET Deleted=1 WHERE PeopleID in ('" & sPerson & "')" sSQL="UPDATE People SET Deleted=0 WHERE PeopleID not in ('" & sPerson & "')"



Jul 19 '05 #7

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

Similar topics

0
3740
by: Frank Collins | last post by:
Can anyone point me to some good examples on the web of using values from dynamically created checkboxes on forms in ASP, particularly relating to INSERTING those values into a SQL or Access database? Basically, I have a form on which I have a series of statements, with 3 checkboxes for each statement - YES, NO, MAYBE. This series of statements is being dynamically populated from a query of a table in Access, called "tblQuestions". In...
1
1624
by: middletree | last post by:
Hate to post this in a separate post, but felt that the last thread was too far down to get noticed. It is called dynamic checkboxes, and it contained some good advice for me, but it led to another question, and I wanted to go ahead and post my question here in hopes of getting an answer. The advice given to me about having a number of checkboxes which are put onto the page from the database, was to name them all the same thing, and...
8
2833
by: DylanM | last post by:
I have some checkboxes that are generated from the results of a database search. At the moment, the checkboxes are part of a table making up a form. Users are going through the form, clicking the boxes and saving to the database at the end with the 'Submit' command button. Is it possible to save the changes as the checkboxes are clicked? I suppose I'd need to write some dynamic ASP event handling at the same time as creating the checkboxes......
7
1952
by: pizzy | last post by:
PROBLEM: I CAN'T GET THE LAST RESUTS TO WORK CORRECTLY. I WOULD PROVIDE THE CODE (AND WILL IF REQUESTED). BUT IN MY OWN WORDS I AM TRYING TO HAVE THE FIRST FORM DYNAMICALLY CREATE INPUT BOXES BASED ON THE NUMBER ENTERED. THEN ON THE SECOND FORM (WHICH IS CREATED BY THE FIRST FORM CALLING A FUNCTION) I WANT THE USER TO BE ABLE TO CLICK ON ONE OF THE CHECKBOXES AND SEE MORE INPUT BOXES APPEAR. HAS ANYONE DONE SOMETHING LIKE THIS? IF SO,...
2
2449
by: trank | last post by:
I created some checkboxes(<input type=checkbox>) dynamically,and then I'd like to access these checkboxes in code behind using C#. For they are not standard controls like Windows Checkbox, I can't catch it by FindControl().....how can i do this? Many thanks a lot! By trank trank@dynamic-x.net
3
3986
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which step you're on. This all works fine, but I ran into some trouble when I started creating controls dynamically in my code-behind file. Each panel contains a table which is filled with various radio buttons, text fields and the such which are...
3
5775
by: Jack Black | last post by:
Using VS.Net 2k3 to build ASP.Net app with VB code-behind pages... Hi, all! I've been struggling with getting a dynamically-generated CheckBoxList generated. I've finally been able to get the list generated, but now there are two problems I haven't been able to overcome: 1) ASP.Net is munging the checkbox ID/Names of the checkboxes: I give it a name like "myCheckbox" and asp.net is creating the checkboxes with the name...
34
3837
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript function needs to run and validate all the checkboxes on my form and make sure none of them are unchecked. I suck at Javascript and my problem is 2fold. I have the following code that constructs the checkbox response.write "<input type=checkbox...
1
4114
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem: I dynamically add an htmlcheckbox to a webform in the pages render and set the checked value to true. When the page loads, if I remove the check from the checkbox and then submit it, in the submit event the checkbox' checked value is still...
0
1518
by: TarekSaad | last post by:
I am using VB2005 and have created a dynamic list of checkboxes and depending on which file the user selects there may be between 1 and 20 checkboxed that appear in a form. The user then checks any number of these checkboxes. I know how many checkboxes exist. I want to scroll down through the check boxes, one after the other and depending on if they are checked or not I different things need to happen. How do I select checkbox 1,...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8968
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4044
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 we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.