Sorry for the misunderstanding. Looking closer at the page, you've got a
checkbox naming issue to deal with.

In a nutshell: 

The way checkboxes work, if you give several checkboxes the same name, you
end up with a comma delimited list of their values. The problem here is that
you need to sync those values up with a policy. Since checkbox values only
get passed when checked, it is VERY easy (and likely) for the values to
become out of sync with the policy that they are supposed to modify.

Each checkbox name must be unique and appropriately tied to the policy. The
best way to do this is to add the name or number of the current policy to
the checkboxes. I don't know what your data looks like so you'll have to
make a decision about how to name the variables.

One other thing, I prefer using numbers instead of words for bit values (use
a 1 or a zero instead of yes and no).

On the action page, you need to loop over the names and evaluate the values,
rip out the policy names and then do your work. 

Here is some sample code that I wrote real quick to demonstrate:

FORM page:

<form action="two.cfm" method="post">
<input type="checkbox" value="1" name="s_P1">
<input type="checkbox" value="1" name="d_P1"> First Policy<br>
<input type="checkbox" value="1" name="s_P2">
<input type="checkbox" value="1" name="d_P2"> Second Policy<br>
<input type="checkbox" value="1" name="s_P3">
<input type="checkbox" value="1" name="d_P3"> Third Policy<br>
<input type="submit" value="go" name="sub">
</form>

ACTION Page (two.cfm)
<cfloop list="#form.fieldnames#" index="i">
<cfif left(i, 1) IS "d" OR left(i, 1) IS "s">
<cfoutput>#i# -- #right(i, len(i) - 2)# --
#evaluate("form.#i#")#</cfoutput><br>
</cfif>
</cfloop>

maybe this will get you moving in the right direction (this code is tested
and should work if you plug it into some test files.) 

Let us know if you have any questions about what is going on here.

Good luck,
Jeremy



> -----Original Message-----
> From: Susan N. Klos [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 02, 2001 12:00 PM
> To: '[EMAIL PROTECTED]'
> Subject: RE: Getting the data from checkboxes into the database
> 
> 
> No, Jeremy, I want this form to be for input only.
> Let me back up a bit.  I have two tables:
> tblPolicy
>  PolicyNumber PK
>  PolicyName 
> 
> tlnkPolicy
>      PolicyID - PK
>      DistrictID - FK from another table
>      PolicyNumber - FK from tblPolicy
>      District - Yes/No
>      School - Yes/No
>      PolicyDesc - will be input if they check other
> 
> The form lists all the Policy Names from tblPolicy.  The 
> checkboxes should
> be blank so that if a particular policy is a District Policy 
> or a School
> policy the user can check the appropriate boxes.  They might 
> check one, both
> or none.
> 
> On the action page I want the checked boxes for whatever 
> policynumbers to go
> into the database as yes.  If a checkbox is not checked it 
> can go in as no
> or stay blank.  And if no checkboxes are checked for any 
> Policy Names I do
> not want a record to be inserted into the database.  Keep in 
> mind the table
> on the form is being generated dynamically from the database.
> 
> I may have the form set up incorrectly to do what I want to 
> do also. Here is
> the full page for the form:
> 
> 
> <CFQUERY NAME="qryPolicy" DATASOURCE="SDFS">
> SELECT tblPolicy.PolicyNumber, tblPolicy.PolicyName, 
> tlnkPolicy.District,
> tlnkPolicy.School
> FROM tblPolicy LEFT JOIN tlnkPolicy ON tblPolicy.PolicyNumber =
> tlnkPolicy.policyNumber
> </CFQUERY>
> 
> 
> 
> 
> <html>
> <head>
> <title>Page 7</title>
> </head>
> 
> <body>
> <form name="TargetGroups" action="ProcessPage7.cfm" method="post">
> <table border="1"><tr><th>District Policy</th><th>School
> Option</th></tr><tr>
> 
> 
> 
> <cfoutput query="qryPolicy">
> 
> <td><input type="hidden" value="#Policynumber#" name="Policynumber">
> <input type="Checkbox" value="yes" name="District"> </td>  (I 
> put yes in
> here at someone else's suggestion)
> <td><input type="Checkbox" value="yes" name="School"> </td>  
> (same here)
> <td><font size="-1" style="TimesNewRoman"> 
> #Policyname#</font></td></tr>
> 
> </cfoutput></table>
> <input type="Submit" value="SUBMIT">
> 
> 
> 
> </form>
> 
> 
> </body>
> </html>
> 
> Here is what I have on the action page so far:
> <cfloop list="#PolicyNumber#" index="i">
> <cfif isdefined("form.district") or isdefined("form.school")>
> <cfquery datasource="#application.db#">
>       Insert into tlnkPolicy (DistrictID, District, School, 
> PolicyNumber)
>       Values ('#session.DistrictID#', '#form.District#', 
> '#form.School#',
> #i#)
> </cfquery>
> </cfif>
> </cfloop>
> 
> --------------------------------------------------------------
> -----------
> This email server is running an evaluation copy of the 
> MailShield anti-
> spam software. Please contact your email administrator if you have any
> questions about this message. MailShield product info: 
www.mailshield.com

-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org

-------------------------------------------------------------------------
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info: www.mailshield.com

-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org

Reply via email to