Multiple Checkboxes
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=3559
Printed Date: 30 March 2026 at 2:26pm Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: Multiple Checkboxes
Posted By: faubo
Subject: Multiple Checkboxes
Date Posted: 15 June 2003 at 3:16pm
|
Hello,
This is teh first time I'm using a multiple checkbox...
I have many options, each of one witha different value.
Question:
How do I add in a DB field something like
1, 2, 4, 5
These numbers correspond to the checkboxes value.
Thanks
------------- http://www.conhecerparaconservar.org - I don't know how to make you click here
|
Replies:
Posted By: Bullschmidt
Date Posted: 16 June 2003 at 12:33am
|
I THINK this would work. Keep the same name for all the checkboxes but still change the values:
<input type="checkbox" name="MyCheckBoxGroup" value="1">
<input type="checkbox" name="MyCheckBoxGroup" value="2">
------------- J. Paul Schmidt, Freelance ASP Web Developer
www.Bullschmidt.com - www.Bullschmidt.com
Classic ASP Design Tips, ASP Web Database Sample (Freely Downloadable)
|
Posted By: faubo
Date Posted: 22 June 2003 at 2:31pm
|
Ok,
it worked.
Now I have a more complicated problem.
I have the slectbox filed in my DB like that "1, 3, 4, 5"
How to read that from the DB and make the boxes checked for an "Edit profile" page?
------------- http://www.conhecerparaconservar.org - I don't know how to make you click here
|
Posted By: ljamal
Date Posted: 22 June 2003 at 3:10pm
How about
<%
strDBField = RS("DBField")
for i = 1 to 5 %>
<input type="checkbox" name="MyCheckBoxGroup" value="<%=i%>" <% if inStr(strDBField,i)>0 then Response.Write " checked" end if %>>
<% next %>
this works from 0-9 but not for 2 or more digit numbers
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: faubo
Date Posted: 22 June 2003 at 3:47pm
|
I will give it a try,
I'm a little dumb dealing with multiple boxes (more than usual I mean)... not sure why...
Why this won't work with more then 9 kinds of selection? I have one with 16 options...
Thanks anyway,
and any more help I will be glad to read, I browse some asp sites and didn't find this in nowhere.
------------- http://www.conhecerparaconservar.org - I don't know how to make you click here
|
Posted By: ljamal
Date Posted: 22 June 2003 at 3:56pm
It won't work with multiple digits because 1, 21, 311, etc all contain 1. When I have more than 0-9 I use the following
<%
strDBField = "|"&Replace(rs("dbfield"),", ","|")&"|"
x=50
for i = 0 to x %>
<input type="checkbox" name="MyCheckBoxGroup" value="<%=i%>" <% if inStr(strDBField,"|"&i&"|")>0 then Response.Write " checked" end if %>>
<%
next
%>
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: faubo
Date Posted: 22 June 2003 at 4:39pm
|

Microsoft VBScript compilation error '800a041f'
Unexpected 'Next'
/TESTES/modelreg2.asp, line 412 next
^
------------- http://www.conhecerparaconservar.org - I don't know how to make you click here
|
Posted By: faubo
Date Posted: 22 June 2003 at 4:45pm
|
Ok, my mistake, solve that next thing.
Now I'm starting to get what are you doing...
But how do you write the name (option) in the side of the box using this? I got 5 box with the of the first one.
------------- http://www.conhecerparaconservar.org - I don't know how to make you click here
|
Posted By: Gullanian
Date Posted: 22 June 2003 at 4:46pm
<% strDBField = "|"&Replace(rs("dbfield"),", ","|")&"|" x=50 for i = 0 to x %> <input type="checkbox" name="MyCheckBoxGroup" value="<%=i%>" <% if inStr(strDBField,"|"&i&"|")>0 then Response.Write " checked" end if %>> WRITE STUFF HERE <% next %>
|
Posted By: ljamal
Date Posted: 22 June 2003 at 5:09pm
I would use an array to store the information like so:
<%
strDBField = "|"&Replace(rs("dbfield"),", ","|")&"|"
x=50
Dim arrCheckbox(50)
arrCheckbox(0) = "whatever goes here"
arrCheckbox(1) = "same as above"
.
.
.
.
arrCheckbox(49) = "stuff goes here"
arrCheckbox(50) = "check box stuff here too"
for i = 0 to x %>
<input type="checkbox" name="MyCheckBoxGroup" value="<%=i%>" <% if inStr(strDBField,"|"&i&"|")>0 then Response.Write " checked" end if %>>
<%=arrCheckbox(i)%>
<%
next
%>
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: faubo
Date Posted: 22 June 2003 at 5:15pm
|
Thanks!!
the 5 option selectbox is working, I'm gonna try the one with 16 now!
------------- http://www.conhecerparaconservar.org - I don't know how to make you click here
|
Posted By: faubo
Date Posted: 22 June 2003 at 5:52pm
|
the 16th options are not working...
It checks the wrong boxes... I test marking 6 of the 2 digit optios (11 to 16)
and it's showing 3 options... 4, 5 and 6
I'm very tired of these damm boxes...
------------- http://www.conhecerparaconservar.org - I don't know how to make you click here
|
Posted By: ljamal
Date Posted: 22 June 2003 at 8:02pm
what is the value of the strDBField varable?
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: faubo
Date Posted: 22 June 2003 at 10:33pm
strDBField = 11, 12, 13, 14, 15, 16
------------- http://www.conhecerparaconservar.org - I don't know how to make you click here
|
Posted By: ljamal
Date Posted: 24 June 2003 at 1:51pm
You need to go back and look at the code for multiple digit boxes posted above. You didn't change the strDBField line to :
strDBField = "|"&Replace(rs("dbfield"),", ","|")&"|"
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: faubo
Date Posted: 25 June 2003 at 3:30pm
|
I hate to post code here but... I'm stuck at this...
strLanguages get's the data from a form.
strLanguages = "|"&Replace("strLanguages",", ","|")&"|"
x=16 Dim arrCheckbox(16) arrCheckbox(0) = LanArabic arrCheckbox(1) = LanCantonese arrCheckbox(2) = LanDutch arrCheckbox(3) = LanFarsi arrCheckbox(4) = LanFinnish arrCheckbox(5) = LanFrench arrCheckbox(6) = LanGerman arrCheckbox(7) = LanGreek arrCheckbox(8) = LanHebrew arrCheckbox(9) = LanItalian arrCheckbox(10) = LanJapanese arrCheckbox(11) = LanKorean arrCheckbox(12) = LanPortuguese arrCheckbox(13) = LanRussian arrCheckbox(14) = LanSpanish arrCheckbox(15) = LanSwedish
for i = 0 to x %> <td width="50%">
<input type="checkbox" name="languages" value="<%=i%>" <% if inStr(strSFeatures,"|"&i&"|")>0 then Response.Write " checked" end if %>><br> <span class="headingwhite"> <% = arrCheckbox(i)%> <br><% next %>
------------- http://www.conhecerparaconservar.org - I don't know how to make you click here
|
Posted By: ljamal
Date Posted: 25 June 2003 at 3:36pm
strSFeatures should be strLanguages
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: faubo
Date Posted: 25 June 2003 at 4:27pm
|
OH MY GOD!!!!!

I'm sorry for all the work I gave to you!
And thanks very very much it's working perfectly!
------------- http://www.conhecerparaconservar.org - I don't know how to make you click here
|
|