calculating age from dob with ajax

Status
Not open for further replies.

felepeg

New Member
Hi to all

i'm using calc pluggin to calculate age from date of birth using the next php code:

$date= '{dbpac1___Fecha_Nacimiento}';
$date = strtotime($date);
$now = time();
$diff = $now - $date;
$years = floor($diff / 31556926);
return $years;

which is working fine except in two cases:
1.- when open the form at start appears the number 43 in the calc field and that number is recorded in the database.
2.- when i click reset in the form, the ajax form doesn't works and keeps the last calculation done from the pluggin

thanks!
 
1.- when open the form at start appears the number 43 in the calc field and that number is recorded in the database.
Add a test to check that $date is not empty at the beginning of your code.

2.- when i click reset in the form, the ajax form doesn't works and keeps the last calculation done from the pluggin
are you sure its not the browser caching the form values?
 
thanks for your answer rob

i'd tryed some php codes for that but nothing hapens, can you please be more specific o give me some example code?

the browser is not caching it, i checked before

thanks again!
 
What do you have "Calc on save only" set to?

For the PHP you gave, I'd recommend "Yes", which should solve issues of getting unexpected results when displaying forms / lists.

I'll check on that issue you reported with Reset on a form.

-- hugh
 
thanks cheesegrits.
i'd set "NO" in "Calc on save only", the problem was solved when i changed to "Yes" but i need to show the age instantly when someone type his date of birth.
for now i just set "yes" in "Calc on save only", but, exist another way to do it without set "yes"?. i mind, could you suggest another code?
 
great!

good news!
i've right cheesegrits, if set yes to "Calc on save only", the ajax pluggin still working!
here is my settings if someone else wants to use it.
 

Attachments

  • Untitled-1.jpg
    Untitled-1.jpg
    90.4 KB · Views: 374
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top