Show and require field if birthday (date field) is less than 18 years old I have a field that should be visible and required if the user selects a date that would make them less than 18 years old. If they are over 18, the field should be hidden and not required. Right now, I am using this:

In birthday.js:

(function ($) {

$(document).ready(function() {
    $('#edit-field-minor-agreement').hide();
});

$(document).on('change', '#edit-field-dob-und-0-value-year, #edit-field-dob-und-0-value-month, #edit-field-dob-und-0-value-day', function() {
    var yyyy = $("#edit-field-dob-und-0-value-year").find(":selected").val();
    var m = $("#edit-field-dob-und-0-value-month").find(":selected").val();
    var d = $("#edit-field-dob-und-0-value-day").find(":selected").val();

    if ( $('#edit-field-dob-und-0-value-year').val() &amp;&amp; $('#edit-field-dob-und-0-value-year').val() &amp;&amp; $('#edit-field-dob-und-0-value-year').val() ){
        dateString = m + "/" + d + "/" + yyyy;
        var today = new Date();
        var birthDate = new Date(dateString);
        var age = today.getFullYear() - birthDate.getFullYear();
        var m = today.getMonth() - birthDate.getMonth();
        if (m &lt; 0 || (m === 0 &amp;&amp; today.getDate() &lt; birthDate.getDate())) {
            age--;
        }   
        console.log("Birth date: " + dateString);
        console.log("Age: " + age);
    }

    if(age&lt;18) {
        $('#edit-field-minor-agreement').show();
    } else {
        $('#edit-field-minor-agreement').hide();
    }

});
})(jQuery);


It is successfully setting the visibility, but I can't seem to figure out how to make it required. Any help is appreciated.
Here is a working solution. Huge thanks to @nikathone for assistance.

/**
 * Implements hook_form_FORM_ID_alter() for record_node_form.
 */
function mrpeanut_form_record_node_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if (!empty($form['field_dob']) &amp;&amp; !empty($form['field_minor_agreement'])) {
    $form['field_minor_agreement']['#prefix'] = '&lt;div id="edit-field-minor-agreement-wrapper"&gt;';
    $form['field_minor_agreement']['#suffix'] = '&lt;/div&gt;';
    $is_younger = TRUE;
    $values = !empty($form_state['values']) ? $form_state['values'] : array();
    $dob_date_combo_element = &amp;$form['field_dob']['und'][0];
    $dob_date_combo_element['#ajax'] = [
      'callback' =&gt; 'mrpeanut_form_record_node_form_minor_agreement_callback',
      'wrapper' =&gt; 'edit-field-minor-agreement-wrapper',
      'effect' =&gt; 'fade',
    ];

    if (!empty($values['field_dob']['und'][0]['value'])) {
      $dob = new DateTime($values['field_dob']['und'][0]['value']);
      $now = new DateTime();
      $age = $now-&gt;diff($dob)-&gt;y;
      $is_younger = $age &lt; 18;
    }

    $form['field_minor_agreement']['und']['#access'] = $is_younger;
    $form['field_minor_agreement']['und'][0]['#required'] = $is_younger;
  }
}

/**
 * Ajax callback for minor agreement.
 */
function mrpeanut_form_record_node_form_minor_agreement_callback($form, $form_state) {
  return $form['field_minor_agreement'];
}