<input type="date" style="width:210px" name="txtdateofbirth" onChange="calage(this.value)" id="txtdateofbirth">
function calage(dob) {
var date1 = new Date();
var y = date1.getFullYear();
var by = dob.split("-",1);
var age = y - by; $("#txtage").html(age);
}
I tried it on jsfiddle but it's not work. Could you give me a correction please?
ReplyDeletehttp://jsfiddle.net/nobuts/3vRvV/
@bonus: Hi bonus. It is nice to see that you are using this code.
DeleteAnd also thank you for asking this question. I am sorry, but I made a mistake. While assigning calculated age to span, we should write $("#txtage").html(age);
And in jsfiddle, you have choose proper js version need to be included and when js code should be added in the page.
Please go through this and observe "Frameworks & Extensions" section at the left:
http://jsfiddle.net/3vRvV/8/