Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery - confirm that a checkbox group has been checked where required
    primarykey
    data
    text
    <p>Could someone show me how to resolve this validation issue please?</p> <p>I'm trying to write a special validation script for an app we are working on. <strong>We don't want to use a jquery val plugin</strong>, for several reasons. It was pretty easy getting the layout of the code, and I have it working for text, text-area and drop-boxes, but I am stuck on the check of checkboxes and radio buttons. I have it coded to find the visiblefield-sets, then find the required [class name will have '-required' in it] check-boxes and radio fields within those visible field-sets. </p> <p>Keeping the same structure of my code, how do I adjust what I have so it will then filter through the above that are not checked and provide the error message before form submission. <strong>Select "Boat" in the Product Type dropdown.</strong> to see required checks and radio fields.</p> <p>I tried the <code>not(':checked')</code>, but that is not working. I'm stuck. Help please.</p> <p><strong>my jsfiddle is here:</strong> <code>http://jsfiddle.net/justmelat/X3CGW/</code></p> <p><strong>html and jquery below:</strong></p> <pre><code> &lt;form method="post" action=""&gt; &lt;div id="holdErrMsg"&gt;&lt;/div&gt; &lt;fieldset id="mainSection" name="mainSection"&gt; &lt;legend style="color:blue; font-weight:bold"&gt;Project Overview Section&lt;/legend&gt; &lt;table style="width: 100%"&gt; &lt;tr&gt; &lt;td style="height: 33px; width: 178px;"&gt;Name&lt;span style="color: red"&gt;*&lt;/span&gt;&lt;/td&gt; &lt;td style="height: 33px"&gt;&lt;input id="1125" name="1125" class="1125-required" type="text" /&gt;1125&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 33px; width: 178px;"&gt;Email&lt;span style="color: red"&gt;*&lt;/span&gt;&lt;/td&gt; &lt;td style="height: 33px"&gt;&lt;input id="1026" name="1026" class="1026-required" type="text" /&gt;1026&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="width: 178px"&gt;Product Title&lt;/td&gt; &lt;td&gt;&lt;input id="1089" name="1089" type="text" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="width: 178px"&gt;Product Type&lt;span style="color: red"&gt;*&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;select id="1169" name="1169" class="1169-required"&gt; &lt;option value=""&gt;Select&lt;/option&gt; &lt;option value="Cars"&gt;Cars&lt;/option&gt; &lt;option value="Boats"&gt;Boats&lt;/option&gt; &lt;option value="Planes"&gt;Planes&lt;/option&gt; &lt;/select&gt;1169&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt; &lt;button id="btnCatchReqFlds" type="button" name="btn"&gt;Check Required Fields&lt;/button&gt; &lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/fieldset&gt; &lt;fieldset id="section-11" name="section-11"&gt; &lt;legend style="color:fuchsia; font-weight:bold"&gt;Car Details Section&lt;/legend&gt; &lt;table cellpadding="2" style="width: 100%"&gt; &lt;tr&gt; &lt;td style="width: 334px; height: 35px"&gt;&lt;label&gt;Size:&lt;span style="color: red"&gt;*&lt;/span&gt;&lt;/label&gt;&lt;/td&gt; &lt;td style="height: 35px"&gt;&lt;input id="1245" class="1245-required" name="1245" type="text" /&gt;1245&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; width: 334px"&gt;Color:&lt;span style="color: red"&gt;*&lt;/span&gt;&lt;/td&gt; &lt;td style="height: 35px"&gt; &lt;select id="1433" class="1433-required" name="1433"&gt; &lt;option value=""&gt;Select&lt;/option&gt; &lt;option value="Orange"&gt;Orange&lt;/option&gt; &lt;option value="Blank"&gt;Blank&lt;/option&gt; &lt;option value="Green"&gt;Green&lt;/option&gt; &lt;/select&gt;1433&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="width: 334px"&gt;Description:&lt;/td&gt; &lt;td&gt; &lt;textarea id="1290" name="1290" rows="2" style="width: 433px"&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/fieldset&gt; &lt;fieldset id="section-12" name="section-12"&gt; &lt;legend style="color:fuchsia; font-weight:bold"&gt;Plane Details Section&lt;/legend&gt; &lt;table cellpadding="2" style="width: 100%"&gt; &lt;tr&gt; &lt;td style="width: 334px; height: 35px"&gt;&lt;label&gt;Size:&lt;/label&gt;&lt;/td&gt; &lt;td style="height: 35px"&gt;&lt;input id="1245" name="1245" type="text" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; width: 334px"&gt;Color&lt;span style="color: red"&gt;*&lt;/span&gt;:&lt;/td&gt; &lt;td style="height: 35px"&gt; &lt;input type="checkbox" name="1433[]" id="1433[]" value="Orange" class="1433[]-required"/&gt;Orange &lt;input type="checkbox" name="1433[]" id="1433[]" value="Blue" class="1433[]-required"/&gt;Blue &lt;input type="checkbox" name="1433[]" id="1433[]" value="Green" class="1433[]-required"/&gt;Green &gt;&gt;1433[] &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="width: 334px"&gt;Description:&lt;/td&gt; &lt;td&gt; &lt;textarea id="1290" name="1290" rows="2" style="width: 433px"&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/fieldset&gt; &lt;fieldset id="section-13" name="section-13"&gt; &lt;legend style="color:fuchsia; font-weight:bold"&gt;Boat Details Section&lt;/legend&gt; &lt;table cellpadding="2" style="width: 100%"&gt; &lt;tr&gt; &lt;td style="width: 334px; height: 35px"&gt;&lt;label&gt;Size:&lt;/label&gt;&lt;/td&gt; &lt;td style="height: 35px"&gt;&lt;input id="1245" name="1245" type="text" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; width: 334px"&gt;Color:&lt;span style="color: red"&gt;*&lt;/span&gt;&lt;/td&gt; &lt;td style="height: 35px"&gt; &lt;input type="radio" name="1834" id="1834" value="None" class="valuetext 1834-required"&gt;None &lt;input type="radio" name="1834" id="1834" value="All" class="valuetex 1834-required"&gt;All &amp;nbsp;&amp;nbsp;|1834[] &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; width: 334px"&gt;Approver:&lt;/td&gt; &lt;td style="height: 35px"&gt; &lt;input type="checkbox" name="1149[]" id="1149[]" value"John Marsh" class="1149[]-not_required"/&gt;John Marsh &lt;input type="checkbox" name="1149[]" id="1149[]" value"Phil Collins" class="1149[]-not_required"/&gt;Phil Collins &lt;input type="checkbox" name="1149[]" id="1149[]" value"Tom Green" class="1149[]-not_required"/&gt;Tom Green |1149[] &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; width: 334px"&gt;Engine:&lt;span style="color: red"&gt;*&lt;/span&gt;&lt;/td&gt; &lt;td style="height: 35px"&gt; &lt;input type="radio" name="1898" id="1898" value="Type 1" class="valuetext 1898-required"&gt;Type 1 &lt;input type="radio" name="1898" id="1898" value="Type 2" class="valuetext 1898-required"&gt;Type 2 &amp;nbsp;&amp;nbsp;|1898 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="width: 334px"&gt;Description:&lt;/td&gt; &lt;td&gt; &lt;textarea id="1290" name="1290" rows="2" style="width: 433px"&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/fieldset&gt;&lt;br&gt; &lt;fieldset id="section-1011" name="section-1011"&gt; &lt;legend style="color:green; font-weight:bold"&gt;Misc Info Section&lt;/legend&gt; &lt;table cellpadding="2" style="width: 100%"&gt; &lt;tr&gt; &lt;td style="width: 334px; height: 35px"&gt;&lt;label&gt;Size:&lt;/label&gt;&lt;/td&gt; &lt;td style="height: 35px"&gt;&lt;input id="1301" name="1301" type="text" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; width: 334px"&gt;Color:&lt;/td&gt; &lt;td style="height: 35px"&gt; &lt;select id="1302" name="1302"&gt; &lt;option value="Orange"&gt;Orange&lt;/option&gt; &lt;option value="Blank"&gt;Blank&lt;/option&gt; &lt;option value="Green"&gt;Green&lt;/option&gt; &lt;/select&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="width: 334px"&gt;Description:&lt;/td&gt; &lt;td&gt; &lt;textarea id="1303" name="1303" rows="2" style="width: 433px"&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/fieldset&gt; &lt;/form&gt; $("#section-11,#section-12,#section-13,#section-1011").hide(); var projtype = new Array( {value : 'Cars', sect_id : 'fieldset#section-11'}, {value : 'Planes', sect_id : 'fieldset#section-12'}, {value : 'Boats', sect_id : 'fieldset#section-13'} ); $("select#1169").on('change',function () { var thisVal = $(this).val(); var sect_id =""; //$('fieldset[id!="mainSection"]').hide(); $(projtype).each(function() { $(this.sect_id).hide(); if(this.value == thisVal) { $(this.sect_id).show(); } }); $("#btnCatchReqFlds").on('click', function() { $("#holdErrMsg").empty(); var chk_requiredButEmpty = $("fieldset:visible").find('input:checkbox[class*="-required"]').filter(function() { return not(':checked'); }); if (chk_requiredButEmpty.length) { chk_requiredButEmpty.each(function () { $("#holdErrMsg").append("Please fill in the " + this.name + "&lt;br /&gt;"); }); } return !chk_requiredButEmpty.length; }); </code></pre> <p>}) ​</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload