?
Solved

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

Posted on 2016-09-08
3
Medium Priority
?
76 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

743 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