Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

335
Views
Javascript .change (función () calcula la edad según la fecha

JavaScript

 <script type="text/javascript"> $(document).ready(function() { $('#dob').change(function() { var dob = new Date(document.getElementById('dob').value); var today = new Date(); var age = Math.floor((today-dob)/(365.25*24*60*60*1000)); document.getElementById('age').value = age; }); }); </script>
 <div class="input-field col s12"> <label for="dob_label">Date of Birth</label></br> <input type="date" name="dob" id="dob" required/> </div> <div class="input-field col s12"> <label for="age_label">age</label></br> <input type="text" name="age" id="age" readonly/> </div>

Esto es lo que he intentado para el cálculo automático de la edad en javaScript, pero parece que la edad de entrada no responde cuando elijo una fecha en la entrada dob. Por favor, hágame saber qué parte me he perdido para esta función.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Compruebe el fragmento de código de ejecución: su código funciona

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> </head> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <body> <script type="text/javascript"> $(document).ready(function() { $('#dob').change(function() { console.log("change"); var dob = new Date(document.getElementById('dob').value); var today = new Date(); var age = Math.floor((today-dob)/(365.25*24*60*60*1000)); document.getElementById('age').value = age; }); }); </script> <div class="input-field col s12"> <label for="dob_label">Date of Birth</label></br> <input type="date" name="dob" id="dob" required/> </div> <div class="input-field col s12"> <label for="age_label">age</label></br> <input type="text" name="age" id="age" readonly/> </div> </body> </html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!