How to autofill a date in one field based on another field selection?

How to autofill a date in one field (text field) based on another field selection (dropdown)?

JB


Jose Barrios


4 Answers

Can you be more specific? Please provide an example of the selections and dates.


David Dagley   

Hi JB,


In your dropdown box, enter the dates as Export Values for each item, and check the "Commit selected value immediately" option.


Next enter this Custom Calculate Script in your text field (changing the dropdown field name accordingly):


event.value=this.getField("Dropdown1").value;





Melanie Garcia   

So you have a drop down field with a number of dates as optional values.

Once some one selects a date that date becomes the value for that drop down field unless you have specified an "optional" value for the date option.

Now how do you want to update the text field?

It can be done immediately as the selection is made or after the user leaves the drop down field.

Another issue could be involved if you distribute your form world wide and need the dates to adjusted for a base location like Greenwich England and then adjusted for the time zone in which you user is located.

If you want to use the selected date in a computation, then this becomes a far more complex task and requires very specific scripting to validate the input date and adjust the date value to a given calendar date.

From your comment you do not want to select the date from the drop down but you want the date that the selection was made on. This is a different action.

I would use the on blur action and have a script that checks the value of the selection and base on whether that value requires a date or returns the selection to the default not selected state either sets the text field to the current date of the user's system or empties the field. Specific coding will require details about field names, values and what action should be taken for each specific value.


George Kaiser   

Select "commit selected values immediately" in the options tab of the drop-down and enter this custom validation script:

if(!event.willCommit)
{
this.getField("text field").value=util.printd("mm/dd/yyyy", new Date())
}


David Dagley   


Please specify a reason: