• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Date age javascript

Date age javascript 1 year 1 week ago #42724

  • dubois
  • dubois's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Hello, I can't fill a text field with the age calculated from the date of a calendar field.
I tried to add this script in css/javascript
<script type="text/javascript">
function birth( ) {
document.getElementById('age').value = document.getElementById('datebirth').value;
}
</script>

and I call my function when I click on next page of the form but I have the following error:
Uncaught TypeError: Cannot read properties of null (reading 'value')
Unfortunately I don't know much about javascript and I can't find my mistake.
If someone has an idea to automatically recover the age I would be really very happy.
THANKS
I have solution :
<script type="text/javascript">
function naissance(age)
{
var jour = document.getElementById('datenaissanced').value;
var mois = document.getElementById('datenaissancem').value;
var annee = document.getElementById('datenaissancey').value;
var dt = new Date(annee,mois,jour);  
var ma_diff = Date.now() - dt.getTime();  
var age_dt = new Date(ma_diff);   
var an = age_dt.getUTCFullYear();  
var age = Math.abs(an - 1970);  
document.getElementById('age').value = age;
alert (age);
 
}   
</script>
Last Edit: 1 year 5 days ago by dubois. Reason: solution
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!