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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add a select all check box in a form.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hi There:

I have made a form which generates a list of checkboxes ..
I need to add a checkbox checking on which all the check boxes displayed should be checked...

can anyone please suggest me the way to do it...i dont know javascript...coldfusion is fine..

Thanks
GG
 
Hey gag_bag,

I think this will do what you want without having to use any JS.

<input type=&quot;checkbox&quot; name=&quot;c1&quot; value=&quot;val1&quot;>
<input type=&quot;checkbox&quot; name=&quot;c1&quot; value=&quot;val2&quot;>
<input type=&quot;checkbox&quot; name=&quot;c1&quot; value=&quot;val3&quot;>
...
<input type=&quot;checkbox&quot; name=&quot;c1&quot; value=&quot;val10&quot;>

<input type=&quot;checkbox&quot; name=&quot;c2&quot; value=&quot;val1,val2,val3,...,val10&quot;>

This will send a list of all values selected to the form in either c1 and/or c2. Just use isdefined() to see if c2 is present. If it is, you can disregard c1 like this:

<cfif isdefined(&quot;c2&quot;)>
<cfset newList=c2>
<cfelse>
<cfset newList=c1>
</cfif>

<cfloop index=&quot;x&quot; list=#newList#>
<cfoutput>#x#<br></cfoutput>
</cfloop>

If having the values in a comma delimited list won't work, there are some other more complicated ways to deal with it though.

Hope this helps,
GJ


 
Hi Gj that was helpful but still my problem is not soled because the form i am fenerating is dynamic and i donnu how many checkboxes are being created...so ur solution cannot be applied can u suggest for this sceanario


thanks a lot

gg.
 
Hey gg,

There's nothing in the code which expects a finite number of checkboxes so it should still work as long as you generate the form in the manner shown above. You can build the &quot;c2&quot; variable during the loop that generates your checkboxes like this:

<cfset c2=&quot;&quot;>
<cfloop...>
<cfset c2=listappend(c2,#currentCheckBoxValue#)>
<checkbox name=&quot;c1&quot; value=&quot;#currentCheckBoxValue#&quot;>
</cfloop>

GJ
 
I did it this way with a text link:

Have a link that sets variable checkall to yes:

<a href=&quot;this_page.cfm?checkall=yes&quot;>Check All</a>

Then in your form check for the existence of that variable:

<input type=&quot;checkbox&quot; <cfif IsDefined('checkall')>checked</cfif> name=&quot;deletethis&quot; value=&quot;#id#&quot;>

If you don't want to refresh the page, you can certainly do this with Javascript - and I'm sure there's a copy and paste script available somewhere out there ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top