如何使用Jquery根据单选按钮选择更改日期选择器字段?

68bkxrlz  于 12个月前  发布在  jQuery
关注(0)|答案(1)|浏览(116)

我有这片HTML,我有5电台选择.根据电台选择结束日期应更新custom_41字段.如果我选择12个月电台的日期字段应更新到12个月从今天起,同样的所有24个月等有人可以帮助请?谢谢

$('#CIVICRM_QFID_1_custom_39').click(function() {
      if ($(this).is(':checked')) {
          $('#CIVICRM_QFID_1_custom_39').prop('checked', true).trigger('click');
var now = new Date();
var day = ("0" + now.getDate()).slice(-2);
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
$('#custom_41').val(today);  
      }
})

个字符

cygmwpex

cygmwpex1#

我改变了你的html代码,输入的值有一个月的值,使它更清晰。你只需要一个输入组的OnClick事件。

<div class="crm-section editrow_custom_39-section form-item" id="editrow-custom_39" style="display: block !important; visibility: visible;">
        <div class="label">
            <label>Monthly Interval</label>
        </div>
        <div class="content">

            <input data-crm-custom="eNach_Payment_Interval:Monthly_Interval"
                   data-api-entity="Contact"
                   data-api-field="custom_39"
                   data-option-edit-path="civicrm/admin/options/eNach_Payment_Interval_Monthly_Interval"
                   class="crm-form-radio"
                   value="12"
                   type="radio"
                   id="CIVICRM_QFID_1_custom_39"
                   name="custom_39">
            <label for="CIVICRM_QFID_1_custom_39">12 Months</label>
            <input data-crm-custom="eNach_Payment_Interval:Monthly_Interval"
                   data-api-entity="Contact"
                   data-api-field="custom_39"
                   data-option-edit-path="civicrm/admin/options/eNach_Payment_Interval_Monthly_Interval"
                   class="crm-form-radio"
                   value="24"
                   type="radio"
                   id="CIVICRM_QFID_2_custom_39"
                   name="custom_39">
            <label for="CIVICRM_QFID_2_custom_39">24 Months</label>
            <input data-crm-custom="eNach_Payment_Interval:Monthly_Interval"
                   data-api-entity="Contact"
                   data-api-field="custom_39"
                   data-option-edit-path="civicrm/admin/options/eNach_Payment_Interval_Monthly_Interval"
                   class="crm-form-radio"
                   value="36"
                   type="radio"
                   id="CIVICRM_QFID_3_custom_39"
                   name="custom_39">
            <label for="CIVICRM_QFID_3_custom_39">36 Months</label>
            <input data-crm-custom="eNach_Payment_Interval:Monthly_Interval"
                   data-api-entity="Contact"
                   data-api-field="custom_39"
                   data-option-edit-path="civicrm/admin/options/eNach_Payment_Interval_Monthly_Interval"
                   class="crm-form-radio"
                   value="48"
                   type="radio"
                   id="CIVICRM_QFID_4_custom_39"
                   name="custom_39">
            <label for="CIVICRM_QFID_4_custom_39">48 Months</label>
            <input data-crm-custom="eNach_Payment_Interval:Monthly_Interval"
                   data-api-entity="Contact"
                   data-api-field="custom_39"
                   data-option-edit-path="civicrm/admin/options/eNach_Payment_Interval_Monthly_Interval"
                   class="crm-form-radio"
                   value="60"
                   type="radio"
                   id="CIVICRM_QFID_5_custom_39"
                   name="custom_39">
            <label for="CIVICRM_QFID_5_custom_39">60 Months</label>

        </div>
        <div class="clear"></div>
    </div>

    <div class="crm-section editrow_custom_41-section form-item" id="editrow-custom_41" style="display: block !important; visibility: visible;">
        <div class="label" style="display: none;">
            <label for="custom_41">
                End Date
                <span class="crm-marker" title="This field is required.">*</span>

            </label>
        </div>
        <div class="content">

            <span class="crm-form-date-wrapper"><input data-crm-custom="eNach_Payment_Interval:Mandate_End_Date" data-crm-datepicker="{&quot;date&quot;:&quot;dd\/mm\/yy&quot;,&quot;minDate&quot;:&quot;2023-01-01&quot;,&quot;maxDate&quot;:null,&quot;time&quot;:false}" aria-label="End Date" name="custom_41" type="text" id="custom_41" class="crm-form-text required crm-hidden-date" placeholder="End Date * " style="display: none;"><input type="text" class="crm-form-text required crm-form-date hasDatepicker" aria-label="End Date" id="dp1698168859281" placeholder="End Date * "></span>

        </div>
        <div class="clear"></div>
    </div>

    <script type="text/javascript">
        $("input[name='custom_39']").change(function () {
            var now = new Date();
            var newDate = new Date(now.getFullYear() + (parseInt($(this).val()) / 12), now.getMonth(), now.getDate());
            $('#dp1698168859281').val(newDate.toDateString());

        });
    </script>

字符串

相关问题