close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

jquery checkbox validation only applies to first checkbox

Thread began 10/27/2014 7:44 am by Nico | Last modified 10/27/2014 4:58 pm by Ray Borduin | 285 views | 1 replies |

Nico

jquery checkbox validation only applies to first checkbox

Hi.
Sorry if this is already replied but coudn't find any answer that solves my issue.
I am trying to apply jquery validation in a checkbox group, but it always applies only to first checkbox.

<input name="futureadditionscol[]" type="checkbox" required id="futureadditionscol_1" title="Please pick at least one" value="1">
a) Default </dd>
<dd><input type="checkbox" name="futureadditionscol[]" id="futureadditionscol_2" value="2">
b) Extra </dd>
<dd> <input type="checkbox" name="futureadditionscol[]" id="futureadditionscol_3" value="3">
c) Special </dd>
<dd><input type="checkbox" name="futureadditionscol[]" id="futureadditionscol_4" value="4">
d) Other


I just need at least one checkbox of the group to be checked.

No matter what I tried (added required to all checkboxes of the group) validation only applies separately to each checkbox. Is there something I have to hand code after I apply the validation rule through jquery validation panel so validation applies to the group and not to each checkbox of the group individually?


Thank you in advance

Sign in to reply to this post

Ray BorduinWebAssist

You could add this script to the bottom of the page to address checkbox groups:

$("#form1").submit(function() {
var noneSelected = true;
$("input[name='futureadditionscol[]']").each(function(ind,el) {
if ($(this).is(':checked')) noneSelected = false;
});
if (noneSelected) {
$("#futureadditionscol_1")[0].setAttribute("required","true");
} else {
$("#futureadditionscol_1")[0].removeAttribute("required");
}
});




make sure to replace my reference to 'form1' with the ID of your form.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...