Solved

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

Posted on 2016-09-08
3
12 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 15

Expert Comment

by:myselfrandhawa
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now