• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

Creating Empty List of Checboxes

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

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
0
Gurpreet Singh Randhawa
Asked:
Gurpreet Singh Randhawa
1 Solution
 
_agx_Commented:
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.

ListCompare: http://cflib.org/udf/ListCompare
<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">
	<cfoutput>
	<cfloop from="1" to="5" index="p">
		<input type="checkbox" value="#p#" name="checkedValueGoing" id-"checkedValueGoing#p#" />
		<input type="hidden" name="allValues" value="#p#">
	</cfloop>
	</cfoutput>
	<input type="submit">
</form>

Open in new window


0
 
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]

0
 
gdemariaCommented:
(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)

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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