Solved

Coldfusion: How to submit a form if all the check boxes are unchecked?

Posted on 2016-09-08
3
29 Views
Last Modified: 2016-09-28
I have a form with a few checkboxes. When submitting without checking at least one checkbox a error happens.   How to submit a form if all the check boxes are unchecked? Thanks.
0
Comment
Question by:Member_2_7971128
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points (awarded by participants)
ID: 41789838
Use cfparam to give it a default value
At the top of your action page, put this for each checkbox:

<cfparam name="form.xxxx" default="">

where xxxx is the name of your input tag for your checkbox.  
This is needed because a checkbox does not send a form variable when it is not checked.   This creates the variable if it does not exist.  If the variable exists, this does nothing
0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 41791469
well what @gde has is correct, another way is you can just use the following in your checkboxes to make it work,

<cfsetting showdebugoutput="false">
<form id="form' name="form">
<input type="checkbox" id="Checkbox1" value = "1" />
<input type="checkbox" id="Checkbox2" value = "2" />
<input type="checkbox" id="Checkbox3" value = "3" />
<input type="checkbox" id="Checkbox4" value = "4" />
<input type="button" id="demo" value = "Demo" />
</form>

<script type = "text/javascript" src = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
		$(document).on("click", "#demo", function () {
			$("input:checkbox:not(:checked)").each(function () {
				$('<input>').attr({type: 'text',id: $(this).attr("id"),name: $(this).attr("id"),value: $(this).val()}).appendTo('form');
				//alert("Id: " + $(this).attr("id") + " Value: " + $(this).val());
			});
		});
	});
</script>

Open in new window


for this $('<input>').attr({type: 'text', you can make it use $('<input>').attr({type: 'hidden',
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 41819428
Best practice to simply provide a value if none is passed.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question