Getting a form field to change when another field changes
Moderator: General Moderators
Getting a form field to change when another field changes
I have three fields, a start time, finish time, and total time. I've worked out the code to do the calculation of the difference, but I don't know how to make the form automatically enter the difference into the total time field. For example, if a use puts 7:00 into the start time, and 8:00 into the finish time, I want 1 to automatically pop up in the third field (totaltime)
My formula is as follows, but I don't know how to make the actual php form auto-update like that. This is probably a total newbie question, but that's what I am.
Thanks
$starttime = strtotime("$start_time_field");
$finishtime = strtotime("$finish_time_field");
$total_time_field = ((($finishtime - $starttime)/60)/60);
My formula is as follows, but I don't know how to make the actual php form auto-update like that. This is probably a total newbie question, but that's what I am.
Thanks
$starttime = strtotime("$start_time_field");
$finishtime = strtotime("$finish_time_field");
$total_time_field = ((($finishtime - $starttime)/60)/60);
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
The quick answer:
The form will have to be submitted for PHP to work its magic. It's server side technology so the information has to be sent back to the server for calculations to be done.
If you want stuff to automatically popup without users having to click a submit button you'll have to use Javascript because it can do things client side.
Mac
The form will have to be submitted for PHP to work its magic. It's server side technology so the information has to be sent back to the server for calculations to be done.
If you want stuff to automatically popup without users having to click a submit button you'll have to use Javascript because it can do things client side.
Mac
Ok, then any suggestions on how I go about this? I am trying to make a form where people enter times into a mysql database. They enter their start time, their finish time, and a total time worked. The kicker is that the total time has to be a real number, hence the formula I posted above.
How should I go about doing this? I have my form and database working, I just can't get the totaltime aspecet worked out.
How should I go about doing this? I have my form and database working, I just can't get the totaltime aspecet worked out.
Ok, the way I would like the form to work is to have the user enter their name, start time, finish time and total time. When they click the submit button, those four items of information go into a database.
The problem I face is that the total time has to be a real number, not a time, so I used this formula to fix that
$starttime = strtotime("$start_time");
$finishtime = strtotime("$finish_time");
$totaltime = ((($finishtime - $starttime)/60)/60);
the problem I face is making that $totaltime result automatically go into the database. I don't want the user to make the calculation, I want them to just have to enter their start and finish times, yet the start, finish, and total times end up in the database. Along with any other info I have in the form.
The problem I face is that the total time has to be a real number, not a time, so I used this formula to fix that
$starttime = strtotime("$start_time");
$finishtime = strtotime("$finish_time");
$totaltime = ((($finishtime - $starttime)/60)/60);
the problem I face is making that $totaltime result automatically go into the database. I don't want the user to make the calculation, I want them to just have to enter their start and finish times, yet the start, finish, and total times end up in the database. Along with any other info I have in the form.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK