Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unchecked checkboxes not registering in loop

Status
Not open for further replies.

fdarkness

Programmer
Feb 17, 2006
110
0
0
CA
I originally posted this in the VBScript forum, but it seems that it's more ASP than VBScript (according to them).

I have the following cludge of code (direct C&P from my page):

Code:
for each key in Request.Form
    if Request(key) = "on" then
        key = 1
    else
        key = 0
    end if
next

I need to set all my form variables for each "key" to 1 or 0 so I can insert it into a table.

The problem is that my loop only seems to register any checkboxes that are checked (ie, "on"). Those that are unchecked don't register in the loop. For example, my sample data produced the following:

Code:
ClientSurveyInvite: 1
UserAdmin: 1
FinancialReporting: 1
Timesheets: 1
Sysadmin: 1

while it *should* have produced the following:

Code:
SearchWarrant: 0
FileReview: 0
OnlineRequestForms: 0
Dashboard: 0
Timesheetmgmt: 0
Timesheets: 1
ClientSurveyInvite: 1
UserAdmin: 1
FinancialReporting: 1
Sysadmin: 1

The variables that are missing in the first sample are those that I had unchecked.

Any idea how I can get it to return *all* the pieces of information in the form, checked or unchecked? So far the only solution that's been offered is setting all the variables to 0 in the first place, then running the loop, resetting those that pop up to 1. But that seems rather silly to me.
 
you wont be able to retrieve unchecked checkboxes in the way you are doing it...

you need to change your form...can you show us your code for the checkboxes...

-DNG
 
here's a quick and dirty sample, for which all the form items are the same:

Code:
<form name="editUser" action="security.asp?function=submitEditUser&userID=<%=UserID%>" method="post">

   <td align=center><input type="checkbox" name="SearchWarrant" <% if objRSSecurity("SearchWarrant")=1 then%> CHECKED <% end if %>></td></tr>

</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top