Calling javascript function from jquery with parameter

Go To


I am working on this code but even after consulting other threads I am not getting the result. It gives some error which causes Apache to throw exception. Here employee is retrieved from a link by $.getJSON(link, handler); and it passes data to handler function.

employeeNumber, fullName, gender etc were pre-existing code and work correctly but when I try to calculate age by calling getAge function in jquery by passing birthDate as parameter, my application crashes. I have tested getAge function in a separate html page where I enter a date in format mm/dd/yyyy and it displays age correctly.

function handler(employee) {
            var bd = new Date(employee.birthDate);
            $('#age').val(employee.birthDate, getAge);


function getAge(dateString) {
        var today = new Date();
        var birthDate = new Date(dateString);
        var age = today.getFullYear() - birthDate.getFullYear();
        var m = today.getMonth() - birthDate.getMonth();
        if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
        return age;

This is a Java Spring application and I am using maven to compile war file.

Thanks and Regards

2012-04-04 16:35
by Yogesh


I'm not sure what your trying to do in this line,

$('#age').val(employee.birthDate, getAge);

I've never seen syntax like that, but I think you where trying to do

2012-04-04 16:42
by Robert Beuligmann