Chekcbox ASP - Any easy ways to handle them

J

JP SIngh

Hi All

I have been asked to do a project which deal with user entering data but
most of the answers are to be added to the database. The forms will be
editable as well so all the checkbox values will have to be retrived and
displayed.

It all seems to be a hell lot of if conditions to me. Does anyone know of a
good way to deal with loads of checkboxes.

Regards
Jas
 
M

McKirahan

JP SIngh said:
Hi All

I have been asked to do a project which deal with user entering data but
most of the answers are to be added to the database. The forms will be
editable as well so all the checkbox values will have to be retrived and
displayed.

It all seems to be a hell lot of if conditions to me. Does anyone know of a
good way to deal with loads of checkboxes.

Regards
Jas

Treat them as an array and use a For loop to process them.
 
A

Aaron Bertrand [SQL Server MVP]

It all seems to be a hell lot of if conditions to me. Does anyone know of
a
good way to deal with loads of checkboxes.

Do they all have unique/similar names, are there several checkboxes with the
same name, where multiple options can be checked?

You can start here...

http://www.aspfaq.com/2036

....but there are certainly ways to make your life easier if you can provide
more details. For example if all of your checkboxes are named similarly,
such as <input name=chk1, chk2, chk3, etc, you can say:

for i = 1 to request.form.count
n = request.form.key(i)
v = request.form.item(i)
if left(n, 3) = "chk" then
' checkbox
response.write "Checkbox " & n & " = " & v & "<br>"
else
' not a checkbox, do other processing
end if
next
 
B

Bullschmidt

Here's a snippet of code from a project I've done with checkboxes that
hopefully might give you some ideas:

<% ' *** Operation %>
<tr>
<td align="right">A surgical procedure or fracture?</td>
<td valign="bottom">
&nbsp;&nbsp;&nbsp;&nbsp;No<input type="radio" name="Operation"
<%= jpsvbBoolToChecked(Operation = False) %> value="No"
onchange="jpsjsSetUnsaved(true);">
Yes<input type="radio" name="Operation" <%=
jpsvbBoolToChecked(Operation = True) %> value="Yes"
onchange="jpsjsSetUnsaved(true);">
</td>
</tr>

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


<<
I have been asked to do a project which deal with user entering data but
most of the answers are to be added to the database. The forms will be
editable as well so all the checkbox values will have to be retrived and
displayed.

It all seems to be a hell lot of if conditions to me. Does anyone know
of a
good way to deal with loads of checkboxes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,075
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top