Hello @nicowob123 ,
Please try this code snippet as MU plugin (as described here https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins )
<?php
add_action( 'wp_footer', 'wpmudev_datepicker_calculate_date', 9999 );
function wpmudev_datepicker_calculate_date() {
global $post;
if ( is_a( $post, 'WP_Post' ) && ! has_shortcode( $post->post_content, 'forminator_form' ) ) {
return;
}
?>
<script type="text/javascript">
jQuery( document ).ready( function($) {
setTimeout(function() {
$('.forminator-custom-form').trigger('after.load.forminator');
},100);
$(document).on('after.load.forminator', function(e, form_id) {
if($('#forminator-module-2910').length) {
$('#date-1 .forminator-datepicker').on('change', function() {
var enteredDate = $(this).val();
var years = new Date(new Date() - new Date(enteredDate)).getFullYear() - 1970;
$('#number-1 input').val(years).trigger('change');
});
}
});
});
</script>
<?php
}
Make sure to change the form ID from 2910 to your form’s ID here → $('#forminator-module-2910')
and change #number-1 input to the ID of you field.
kind regards,
Kasia