These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Recalculating form field data

LiamC
Registered: Jan 11 2009
Posts: 6

Hi,

I am designing a form to submit to a hospital as a request for an obstetric US scan. Two of the fields directly relate on the form, LNMP (the first day of the last menstrual period) and EDD (the estimated due date) these fields are exactly 40 weeks apart.

In the calculation fields of either box I placed this script;

var strStart = this.getField("LMNP/EDD").value;
if(strStart.length)
{
var dateStart = util.scand("dd/mm/yy",strStart);
var fW = 24 * 60 * 60 * 1000 * 7 * 40;
var dueMillis = dateStart.getTime() + fW;
var dueDate = new Date(dueMillis);
event.value = util.printd("dd/mm/yy",dueDate);
}
else
event.value = "NA";

This accurately calculates the other box when data is entered into one although upon re-entry (if someone has made a mistake and needs to change it) one box predominates and only that one can change the data.

(i.e. If data is entered into the LMNP it reverts to the date already there based upon the EDD.)

I have attempted to make a reset button but these form fields can't be left blank as a warning appears after every action if the fields have nothing in them.

I'm stuck now.... help!

My Product Information:
Acrobat Standard 7.0.3, Macintosh
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Are you saying that you want to allow the user to enter a date in the EDD field and have the LMNP field calculated?

George
LiamC
Registered: Jan 11 2009
Posts: 6
I can do that. But I want them to have the choice of entering it into either field and having the other automatically calculated. When I put the script into both calculation boxes one always predominates and if there is already a date in the EDD box the LNMP box is unable to be changed as instead of accepting the user entered value, it recalculates itself from the EDD box.

Is there a way of reseting the date boxes without them bringing up a warning?

Thanks

Liam
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
So what you're wanting is for two fields to be dependent upon each other, as opposed to the EDD field merely being dependent upon the value of the LNMP field. You should not try to use Calculate event of either field to control this. Calculated fields should be set to read-only so the user cannot attempt to change their value.

You can use each field's Validate event to update the other field when its value changes, but this can easily lead to circular reference situation (aka recursion), so you have to be careful and code it correctly.

If you really want to allow the user to enter a value in the EDD field to determine the LNMP date, then post again for some pointers.

George
LiamC
Registered: Jan 11 2009
Posts: 6
Yes, the two fields are dependent on each other although I am unsure of how to use the validate event to do this. Also, the form is used for other medical imaging exams and so these fields are redundant when, say, a CT is selected. However, even whilst hidden and not required the computer prompts you to enter the date in the correct format, when the field is left blank.

Any ideas?

This help is much appreciated!

Liam