This topic is locked
[SOLVED]

 Calculating age in form

4/6/2012 8:01:09 PM
PHPRunner General questions
M
marfal1811 author

I'm using javascript onload event - PHPRunner 6.

Calculate age between date of sale and date of birth

Age but not depart correct values​​. Where is the error.?

thanks
function OnPageLoad(pageid)

{

var ctrlfecha_venta = Runner.getControl(pageid, 'fecha_venta');

var ctrlfecha_nacimiento_c = Runner.getControl(pageid, 'fecha_nacimiento_c');

var ctrledad_c = Runner.getControl(pageid, 'edad_c');

function func() {

ctrledad_c.setValue((ctrlfecha_venta.getValue() -

ctrlfecha_nacimiento_c.getValue())/(365606024)); ---> (1000606024)/365

};

ctrlfecha_nacimiento_c.on('keyup', func);

ctrlfecha_venta.on('keyup', func);

// Place event code here.

// Use "Add Action" button to add code snippets.
} // function OnPageLoad

M
marfal1811 author 4/6/2012



Check this article for inspiration: http://www.codeproject.com/Articles/18317/How-to-calculate-difference-between-two-dates-usin


Thanks Cristian error was here "(1000 60 60 * 24) / 365" worked perfect

S
seeunextweek124 6/3/2012

Hi,
how can i calculate the age from a person. I am testing out a new platform i am building. The system is public (no login, no users etc). If a someone enters data in the format 01/02/1985 for date of birth how can i calculate on the fly with JS onload event the age of him/her and set that in the corresponding field " age " for example. I checked the api but do not know how to accomplish that. Please advice. How to stripe out the 01/02/ ?
Thanks in advance.

J
joiresende 6/4/2012

var ctrlAge = Runner.getControl(pageid, 'age_field');

var ctrlDate = Runner.getControl(pageid, 'date_of_birth');

now = new Date();

function func() {

var dateofbirth=new Date(ctrlDate.getValue());

var age=now.getFullYear()-dateofbirth.getFullYear();

if (now.getMonth()<dateofbirth.getMonth()) {

age=age-1;

}

ctrlAge.setValue(age);

};
ctrlAge.on('click', func);