Hello group, me again,
I have this js code from the udemy course that updates the age field of the employee table.
The code works if I do a save but will not update the 'age' field after selecting a new BirthDate .
I believe it is supposed to update the form on a new selection then the DB on the save.
here is the code in the 'employee-dv.js' file
$j(function(){
$j('#Age').prop('readonly',true);
$j('#BirthDate-dd,#BirthDate-mm,#BirthDate').change(function(){
var dob = get_date('BirthDate');
var today = new Date();
var age = Math.floor((today-dob) / 1000/60/60/24/365.25);
$j('#Age').val(age);
});
$j('#BirthDate').change();
});
Thanks for any direction you can offer,
Bill Walker
Detail view field calculation update issue
Re: Detail view field calculation update issue
Hi,
I think you are missing the get_date function (at least in your post)
Also please use the code formating feature to put your code in the post. This makes reading easier.
I think you are missing the get_date function (at least in your post)
Also please use the code formating feature to put your code in the post. This makes reading easier.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: Detail view field calculation update issue
The get_date function is in the footer-extras.php file as it is used in multiple places.
Here is it's code:
<script>
function get_date(date_field){
var y = $j('#'+ date_field).val();
var m = $j('#'+ date_field + '-mm').val();
var d = $j('#'+ date_field + '-dd').val();
var date_object = new Date(y, m - 1, d);
if(!y) return false;
return date_object;
}
</script>
I will have to investigate the code formatting feature.
Thank you.
Here is it's code:
<script>
function get_date(date_field){
var y = $j('#'+ date_field).val();
var m = $j('#'+ date_field + '-mm').val();
var d = $j('#'+ date_field + '-dd').val();
var date_object = new Date(y, m - 1, d);
if(!y) return false;
return date_object;
}
</script>
I will have to investigate the code formatting feature.
Thank you.
Re: Detail view field calculation update issue
OK, so this is getting strange. None of this code is even being called. I have commented out the whole function and yet the AGE is still getting calculated on SAVE only. So where is this coming from? That is what I need to figure out.
I will report back any results found.
Thanks
I will report back any results found.
Thanks
Re: Detail view field calculation update issue
Hi
Does the line
var dob = get_date('BirthDate');
need to be
var dob = get_date('#BirthDate');
~Paul
Does the line
var dob = get_date('BirthDate');
need to be
var dob = get_date('#BirthDate');
~Paul
Re: Detail view field calculation update issue
The code is fine. The error must be somewhere else. Check for other error like upper/Lowecase mismatch, Errors in the console.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.