Creating Empty List of Checboxes

<cfif condition1 EQ "">
      <cfset checkedornot = "checked">
      <cfset checkedornot = "">
<cfloop from="1" to="5" index="p">
<input type="checkbox" value="#p#" name="checkedValueGoing" id-"checkedValueGoing#p#" #checkedornot# onclick="getAll(#p#,this.form)" />

Now the above is working for all checkboxes and single checkbox also, i mean i can click on the global checkbox button and it will call the function i specified in the onClick event which will just check/uncheck the dependent checkboxes, the same function runs on single checbox selection also and it refershes the page, i had to do a refresh to capture the checkbox as a list and pass them to the DB

Now the issue, if i do the checked all and  form gets submitted, the value of the checkboxes pass a comma separated list, so far so good!

now if i uncheck all the checkboxes and submits the form, the value goes as empty string, while i stiull want to capture the values of the unchecked checkboxes

please guide
LVL 16
Gurpreet Singh RandhawaWeb DeveloperAsked:
Who is Participating?
i stiull want to capture the values of the unchecked checkboxes

As you know, checkboxes don't work that way. What exactly is your goal, to have 2 lists: checked values / unchecked values?

If you really need the _unchecked_ values, there's several ways you could do it. All depends on your ultimate goal though ..

a) add a js function that captures the values of _unchecked_ boxes and stores it in a hidden field
b) store all checkbox values in a hidden field. then on the action page, compare the two lists to get the difference.

<cfparam name="form.allValues" default="">
<cfparam name="form.checkedValueGoing" default="">

checked values <cfdump var="#checkedValueGoing#"><br>
all values <cfdump var="#allValues#"><br>
unchecked values <cfdump var="#listCompare(allValues, checkedValueGoing)#">
<form method="post">
	<cfloop from="1" to="5" index="p">
		<input type="checkbox" value="#p#" name="checkedValueGoing" id-"checkedValueGoing#p#" />
		<input type="hidden" name="allValues" value="#p#">
	<input type="submit">

Open in new window

Gurpreet Singh RandhawaWeb DeveloperAuthor Commented:
this line!

<input type="checkbox" value="#p#" name="checkedValueGoing" id-"checkedValueGoing#p#" />

is like this

<input type="checkbox" value="#p#" name="checkedValueGoing" id-"checkedValueGoing#p#"onclick="getAll(#p#,this.form)"  />

which calls one js function whcih checks and unchecks the multiple checkboxes and reload the page, now this function is written for each single checbox and for comman checkboxes [i mean one click and check/uncheck all]

(no points)

myselfrandhawa, agx's solution of storing all values in a hidden field will allow you to know which ones have not been checked.    When posted, you will have ...

a list of all values
a list of checked values

then you can easily derrive a list of not-checked values (the values that are on the 2nd list but not on the first)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.