[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

Variable error with unchecked checkboxes.

Good afternoon all ~

I'm stumped on why I keep getting the "Variable form.Loss1 is undefined." error message.  Please look at my code and advise.

Thanks.

FORM [in part]

<input type="checkbox" name="Win#curRow#" id="Win" value="1">
<input type="checkbox" name="Loss#curRow#" id="Loss" value="1">
<input type="checkbox" name="Tie#curRow#" id="Tie" value="1">
<input type="checkbox" name="NoPlay#curRow#" id="NoPlay" value="1">

For the first row, only "Win" is checked. (If I check all the checkboxes, the form processes correctly.)  

PROCESS

<cfparam name="form.Win" default="0">
<cfparam name="form.Loss" default="0">
<cfparam name="form.Tie" default="0">
<cfparam name="form.NoPlay" default="0">
<cfloop from="1" to="#form.totRows#" index="i">
      <cfquery name="enterStats" datasource="#datasource#">
         INSERT INTO prstandings (teamID, leagueID, GameDate, Win, Loss, Tie, NoPlay, Runs)  
         VALUES (
         '#evaluate("form.teamID" & i)#',
         '#evaluate("form.leagueID" & i)#',
         '#form.GameDate#',
         '#evaluate("form.Win" & i)#',
         '#evaluate("form.Loss" & i)#',  
         '#evaluate("form.Tie" & i)#',
         '#evaluate("form.NoPlay" & i)#',
         '#evaluate("form.Runs" & i)#'
         )      
         </cfquery>
</cfloop>
0
kbtudor
Asked:
kbtudor
  • 3
1 Solution
 
mrichmonCommented:
Checkboxes are only defined in checked.

So to get the value on form submit youdo:

IsDefined(checkboxName)

Your cfparams are useless since you dynamically name your boxes.  You could place it in the loop to have it work.


In your case don't use evaluate anyway for any fields.  DO this:
<cfloop from="1" to="#form.totRows#" index="i">
<cfparam name="form.Win#i#" default="0">
<cfparam name="form.Loss#i#" default="0">
<cfparam name="form.Tie#i#" default="0">
<cfparam name="form.NoPlay#i#" default="0">
     <cfquery name="enterStats" datasource="#datasource#">
        INSERT INTO prstandings (teamID, leagueID, GameDate, Win, Loss, Tie, NoPlay, Runs)  
        VALUES (
        '#Form["teamID" & i]#',
        '#Form["leagueID" & i]#',
        '#form.GameDate#',
        '#Form["Win" & i]#',
        '#Form["Loss" & i]#',  
        '#Form["Tie" & i]#',
        '#Form["NoPlay" & i]#',
        '#Form["Runs" & i]#'
        )    
        </cfquery>
</cfloop>
0
 
mrichmonCommented:
Checkboxes are only defined in checked.

should have been

 Checkboxes are only defined IF checked.
0
 
kbtudorAuthor Commented:
Excellent!  I appreciate your explanation as well - this helped a lot.
0
 
mrichmonCommented:
glad to have helped.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now