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 bkrike 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
CA
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: 1
FileReview: 1
OnlineRequestForms: 1
Dashboard: 1
Timesheetmgmt: 1
Timesheets: 1
ClientSurveyInvite: 1
UserAdmin: 1
FinancialReporting: 1
Sysadmin: 1

The variables that are missing 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?
 
well, unchecked means unchecked. you can set it in your program, if it's checked, the value for that field is checked, otherwise set it to unchecked. that's like saying the value of a field is 1 or 2. if you check for 1, and it's not 1, then it's got to be 2. lol
 
Um... I have no idea what you just said. It doesn't make any sense.

My "for each" statement checks the values and sets it to either 1 or 0. The problem is that the for each statement doesn't register those checkboxes which are not checked, so they cannot enter the loop to begin with, therefore they are not assigned a value. Does that explain it better?
 
Why not asking in the ASP forum: forum333 ?
This is asp code, isn't it ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV: because I thought it was a VBScript issue. Yes, it's part of an ASP page, but I figured the bulk of the code was VBScript. If you think I'd get a better answer in the ASP forum, then I'll run it over there.
 
[1] Your loop, though figurative in nature, have key reassign like that is strange! But that's is not my main advice.

[2] To get what you have in mind, in your form design, you have to device a parallel set of hidden input fields. I would suggest something like this with a naming convention in place for easy scripting.
[tt]
<input type="checkbox" name="SearchWarrant" onclick="this.form.elements['x-'+this.name].value=(this.checked)?'on':'off'">Search Warrant<br />
<input type="checkbox" name="FileReview" onclick="this.form.elements['x-'+this.name].value=(this.checked)?'on':'off'">File Review<br />
<input type="checkbox" name="OnlineRequestForms" onclick="this.form.elements['x-'+this.name].value=(this.checked)?'on':'off'">Online Request Forms<br />
<input type="checkbox" name="Dashboard" onclick="this.form.elements['x-'+this.name].value=(this.checked)?'on':'off'">Dashboard<br />
<input type="checkbox" name="Timesheetmgmt" onclick="this.form.elements['x-'+this.name].value=(this.checked)?'on':'off'">Timesheet Management<br />
<input type="checkbox" name="Timesheets" onclick="this.form.elements['x-'+this.name].value=(this.checked)?'on':'off'">Timesheets<br />
<input type="checkbox" name="ClientSurveyInvite" onclick="this.form.elements['x-'+this.name].value=(this.checked)?'on':'off'">Client Survey Invitation<br />
<input type="checkbox" name="UserAdmin" onclick="this.form.elements['x-'+this.name].value=(this.checked)?'on':'off'">User Admin<br />
<input type="checkbox" name="FinancialReporting" onclick="this.form.elements['x-'+this.name].value=(this.checked)?'on':'off'">Financial Reporting<br />
<input type="checkbox" name="Sysadmin" onclick="this.form.elements['x-'+this.name].value=(this.checked)?'on':'off'">System Admin<br />

<input type="hidden" name="x-SearchWarrant" value="off">
<input type="hidden" name="x-FileReview" value="off">
<input type="hidden" name="x-OnlineRequestForms" value="off">
<input type="hidden" name="x-Dashboard" value="off">
<input type="hidden" name="x-Timesheetmgmt" value="off">
<input type="hidden" name="x-Timesheets" value="off">
<input type="hidden" name="x-ClientSurveyInvite" value="off">
<input type="hidden" name="x-UserAdmin" value="off">
<input type="hidden" name="x-FinancialReporting" value="off">
<input type="hidden" name="x-Sysadmin" value="off">
[/tt]
Then you get all the info directly from the hidden field "x-...". If you still don't get the essential idea, you have then to ask asp forum for more advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top