Jquery Date calculation not working on clone
Currently working on calculating the expeerience using jquery date picker from date and to date. For example (
if user select the date 01/05/2010 (from) - (To) 31 / 07 / 2013 -- result will be 3years and 3 months
) the result will be shown in label format. Again when the user click add more button one more row will be generated here also the user enter the from date and to date. The resule will be both the two rows (
if user select the date 01/05/2010 (from) - (To) 31 / 07 / 2013 -- result will be 6years and 6 months
) it has to calulate both rows.
Here is the Jquery code which wrote for the current calculation
$(document).on('change', "#txt_Tdob", function (){ var date1 = document.getElementById("txt_Fdob").value; var date2 = document.getElementById("txt_Tdob").value; var x = date1.split("-"); var y = date2.split("-"); var fromdate = new Date(x[2], x[0] - 1, x[1]); var todate = new Date(y[2], y[0] - 1, y[1]); var diffDays = parseInt((todate - fromdate) / (1000 * 60 * 60 * 24)); var year = parseInt(diffDays / 365); var date = diffDays - (365 * year); var month = parseInt(date / 30); document.getElementById("txt_expy").innerHTML = year + " year"; document.getElementById("txt_expm").innerHTML = month + " Month"; });
http://jsfiddle.net/karthic2914/ezm4hty2/2/
Thanks & Regards
Mahadevan