How to set value of age textbox by using javascript/jquery -


i have

<input type="text" name="age" value="" enabled="false">` paired `<input type="date" name="birthdate"> 

i want set age text box value difference of present date , date user has inputted automatically date using either javascript or jquery

try : can calculate age on change of birth date selected user. take difference between time , calculate year , month . note - calculated year , month approximate, op should change code accordingly.

$(function(){    var calculateage = function(time){      var months = math.round(time/(24*60*60*1000*30));      //alert(months);      var years = parseint(months / 12);      //alert(years);      months = months % 12;      return years +" yrs , " + months + " months";    };      $('input[name="birthdate"]').change(function(){         var birthdate = new date($(this).val()).gettime();         var presentdate = new date().gettime();         //alert(birthdate);         //alert(presentdate);         var age = presentdate - birthdate;         $('input[name="age"]').val(calculateage(age));    });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>  <input type="text" name="age" value="" enabled="false">   <br/>paired <input type="date" name="birthdate">


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -