469,271 Members | 997 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

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(strSQL)

strTempRow = 0
While Not RS.EOF
Response.Write "<td colspan=2><input type=checkbox
value='"&RS.Fields("PeopleID")&"'>"&RS.Fields("Peo pleDesc")&"</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 4305
Response.Write "<td colspan=2><input type=checkbox
name = 'chkSomething" & strTempRow & "'
value='"&RS.Fields("PeopleID")&"'>"&RS.Fields("Peo pleDesc")&"</td>"
strTempRow = strTempRow + 1
--
Roji. P. Thomas
SQL Server Programmer
--------------------------------------
"middletree" <mi********@htomail.com> wrote in message
news:%2****************@TK2MSFTNGP09.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(strSQL)

strTempRow = 0
While Not RS.EOF
Response.Write "<td colspan=2><input type=checkbox
value='"&RS.Fields("PeopleID")&"'>"&RS.Fields("Peo pleDesc")&"</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<%=trim(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.Fields("PeopleID")%>">
which gives <input type=checkbox name=Person value="1">
then on the following page, I Request.Form("Person") 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********@htomail.com> wrote in message
news:%2****************@TK2MSFTNGP09.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(strSQL)

strTempRow = 0
While Not RS.EOF
Response.Write "<td colspan=2><input type=checkbox
value='"&RS.Fields("PeopleID")&"'>"&RS.Fields("Peo pleDesc")&"</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********@somewhere.com> wrote in message
news:Oq**************@TK2MSFTNGP11.phx.gbl...
Response.Write "<td colspan=2><input type=checkbox
name = 'chkSomething" & strTempRow & "'
value='"&RS.Fields("PeopleID")&"'>"&RS.Fields("Peo pleDesc")&"</td>"
strTempRow = strTempRow + 1
--
Roji. P. Thomas
SQL Server Programmer
--------------------------------------
"middletree" <mi********@htomail.com> wrote in message
news:%2****************@TK2MSFTNGP09.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(strSQL)

strTempRow = 0
While Not RS.EOF
Response.Write "<td colspan=2><input type=checkbox
value='"&RS.Fields("PeopleID")&"'>"&RS.Fields("Peo pleDesc")&"</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*****@hotmail.com> wrote in message
news:#b**************@tk2msftngp13.phx.gbl...
2) <input type=checkbox name=Person value="<%=RS.Fields("PeopleID")%>">
which gives <input type=checkbox name=Person value="1">
then on the following page, I Request.Form("Person") 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=Request.Form("PeopleGroups")
arrPeopleGroups=SPLIT(sPeopleGroups,",")

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

For iLoop = 0 to UBound(arrPeopleGroups)
sSQL="INSERT INTO tblPeopleGroupsSelected (parentID, selectedID)
VALUES(" & lngIdentity & ", " & arrPeopleGroups(iLoop) & ")"
connectionObject.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 tblPeopleGroupsSelected (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 tblPeopleGroupsSelected 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********@htomail.com> wrote in message
news:O5****************@TK2MSFTNGP12.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*****@hotmail.com> wrote in message
news:#b**************@tk2msftngp13.phx.gbl...
2) <input type=checkbox name=Person value="<%=RS.Fields("PeopleID")%>"> which gives <input type=checkbox name=Person value="1">
then on the following page, I Request.Form("Person") 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*****@hotmailXXX.com> wrote in message
news:#k**************@TK2MSFTNGP10.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=Request.Form("PeopleGroups")
arrPeopleGroups=SPLIT(sPeopleGroups,",")

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

For iLoop = 0 to UBound(arrPeopleGroups)
sSQL="INSERT INTO tblPeopleGroupsSelected (parentID, selectedID)
VALUES(" & lngIdentity & ", " & arrPeopleGroups(iLoop) & ")"
connectionObject.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 tblPeopleGroupsSelected (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 tblPeopleGroupsSelected 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********@htomail.com> wrote in message
news:O5****************@TK2MSFTNGP12.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*****@hotmail.com> wrote in message
news:#b**************@tk2msftngp13.phx.gbl...
2) <input type=checkbox name=Person

value="<%=RS.Fields("PeopleID")%>"> which gives <input type=checkbox name=Person value="1">
then on the following page, I Request.Form("Person") 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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Frank Collins | last post: by
3 posts views Thread by Leo J. Hart IV | last post: by
3 posts views Thread by Jack Black | last post: by
34 posts views Thread by clinttoris | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.