samedi 20 février 2021

How to clear checkbox and alert if I select YES or NO?

I have a set of list selection field above as YES and NO within a fieldset. And a set of checkboxes in another fieldset below.

What I expect to happen via a jquery is

  • If I select NO in the list above, an alert should appear and checkboxes below will clear out. I have tried the following but not able to get it work. Can anyone help please? Thanks
     $('#enable_email').change(function() {
     if ($('#enable_email').attr("value")=="NO"))) {
          Swal.fire({
              title: 'Alert'
            });
    $("input[name=group_101]").removeAttr('checked');
          }
<div class="crm-communications-preferences-form-block crm-public">
    
        <div class="comm-pref-block groups-block">
    
        <fieldset id="crm-communications-preferences-channels">
            <div class="crm-section">
            <div class="label"><label for="enable_email">  Email Newsletter
         <span class="crm-marker" title="This field is required.">*</span>
    </label></div>
            <div class="content"><select name="enable_email" id="enable_email" class="crm-form-select required">
        <option value="">--Select--</option>
        <option value="YES" selected="selected">Yes</option>
        <option value="NO">No</option>
    </select></div>
          </div>
                        </fieldset>
                </div>
    </div>

        <!-- Groups from settings -->
        <div class="comm-pref-block groups-block">
    
            <!-- Groups Fieldset -->
    <fieldset id="crm-communications-preferences-groups" class="groups-fieldset">
    <div class="crm-section">
    <div class="content group-channel-div">
    <input id="group_101" name="group_101" type="checkbox" value="1" checked="checked" class="crm-form-checkbox">
<label for="group_101">Newsletter</label>
        <span class="group-description">Monthly Newsletter</span>
                 </div>
                  </div>
    <div class="crm-section">
    <div class="content group-channel-div">
    <input id="group_102" name="group_102" type="checkbox" value="1" checked="checked" class="crm-form-checkbox">
                        <label for="group_102">Communications</label>
        <span class="group-description">Relating Activities</span>
                 </div>
                  </div>
                </fieldset>
                </div>
    </div>




Aucun commentaire:

Enregistrer un commentaire