Top Ad unit 728 × 90

Checking whether a checkbox is checked using jquery

HTML form:

<div id="divHfaEnhance" class="asen-form-row">
          <ul class="asen-form-list inline">
           <h4>20. b. In case of enhancement, please specify enhancement required</h4>
            <li>
                  <input type="checkbox" name="chkER[]" value="1" checked>    <label>One Room (1)</label>
                  <input type="checkbox" name="chkER[]" value="2" checked> <label>Kitchen (2)</label>
                  <input type="checkbox" name="chkER[]" value="3" > <label>Bath (3)</label>
                  <input type="checkbox" name="chkER[]" value="4" > <label>Toilet (4)</label>
              </li>
            </ul>
  </div>

JQuery:
              function getCheckedVals() {        
                 var allVals = [];
                 $('#divHfaEnhance :checked').each(function() {
                   allVals.push($(this).val());
                   singleVal = $(this).val(); //alert("singleVal "+singleVal);
                   if(singleVal === '1'){ One_Room = 'Yes'; }
                   else if(singleVal === '2'){ Kitchen = 'Yes'; }
                   else if(singleVal === '3'){ Bath = 'Yes'; }
                   else if(singleVal === '4'){ Toilet = 'Yes'; }
                 });
                 //alert(allVals);
                 Comb_Code = allVals.join(''); //alert("Comb_Code "+Comb_Code);

                 if(One_Room === undefined) { One_Room = 'No'; } //alert("One_Room "+ One_Room);
                 if(Kitchen === undefined){ Kitchen = 'No'; } //alert("Kitchen "+ Kitchen);
                 if(Bath === undefined){ Bath = 'No'; }  //alert("Bath "+ Bath);
                 if(Toilet === undefined){ Toilet = 'No'; } //alert("Toilet "+ Toilet);
              }
             $(function() {
               $('#divHfaEnhance input').click(getCheckedVals);
               getCheckedVals();
             });


You can try this in your project. It works!
Checking whether a checkbox is checked using jquery Reviewed by Ashok Sen on 23:52:00 Rating: 5

No comments:

Website Design Company at Kolkata All Rights Reserved © 2014 - 2019
Developed by Asenwebmedia

Contact Form

Name

Email *

Message *

Powered by Blogger.