Solved

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

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
COLD FUSION 6 29
How to display Coldfusion alert message box icons 8 662
How to determine if Javascript/Jquery is not working? 22 92
ajaxSubmit is giving me an error 1 54
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…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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