Php syntax in button

I created a php button in a form to calculate the difference between two time values entered in the form. I would like to add some kind of submit button to allow the calculated value to be entered automatically in the same form. Is it possible? or is there another way of doing it?
So far, the form looks like this:
The php button “Calculer temps” is:

$d1 = {fin};
$d2 = {debut};
$d1_timestamp = strtotime($d1);
$d2_timestamp = strtotime($d2);
$time = ($d1_timestamp - $d2_timestamp) / 60 / 60;

echo “Total de $time heures”;

It opens in a new window and I would like the OK button (or to add a new one) to enter the $time value in the nb_heures fields in the form…

I tried to code a button in php but I get this error : Parse error: syntax error, unexpected ‘<’ in /opt/NetMake/v7/wwwroot/scriptcase/app/feuille_de_temps/form_temps/form_temps_apl.php on line 1190

I am not a programmer and I am learning to use both scriptcase, php and mysql. So any help would be appreciated.

If there is another way to calculate the value and to add it in the form, I am open to ideas.

Screenshot - 14-02-13 - 04:46:26 PM.png

One option would be to create an onchange event on the latest date and perform the calculation. The result of the calculation can be put into a formfield. If you need a new field you can just create one and use this as a placeholder.

Thank you for your suggestion. I think that would work even better than what I had in mind. If I am not mistaken, that would be done using an ajax event? I am reading a tutorial about ajax right now, as I never used it before.

I think I am going to need some help as to how to put the result of the calculation into the formfield. Is it with the option “Fields that will be passed as parameters” in the ajax event?

Your help is greatly appreciated.

[QUOTE=jonathan;21461]Thank you for your suggestion. I think that would work even better than what I had in mind. If I am not mistaken, that would be done using an ajax event? I am reading a tutorial about ajax right now, as I never used it before.

I think I am going to need some help as to how to put the result of the calculation into the formfield. Is it with the option “Fields that will be passed as parameters” in the ajax event?

Your help is greatly appreciated.[/QUOTE]

Actually yes, it’s an ajax event, but you just enter php which is executed by ajax. But the difficult thing is hidden for you so you just can enter the necessary php. To fill the field on the screen you use {myfield}=$mycalculation;

Thanks again for your help, it is really appreciated.
Everything is working perfectly now.