Skip to main content
Known Participant
June 22, 2016
Answered

Pick lowest Age

  • June 22, 2016
  • 1 reply
  • 797 views

Hi, i have 9 date fields in "mm/yyyy" format. so i want Pick lowest Age. can u pls help me. thanks..

my form fields.

age of account1

age of account2

age of account3

age of account4

age of account5

age of account6

age of account7

age of account8

age of account9

This topic has been closed for replies.
Correct answer gkaiseril

The value you are trying find the youngest age is considered string type of variable. The minimum method requires numeric values. The "/" in the value makes it a string. You can either alphabetically sort the data or convert the dates to sequential numbers using the JavaScript Date object.  Have you tried different entry values to see how the age field fills in?

Entering a value of "1/2000" will display as "01/2000" but have a value of "1/2000". This missing leading zero could cause a sort problem.


See YoungestDateValues to see the results of 4 different ways to perform the task. Only 3 will provide the correct result.

1 reply

try67
Community Expert
Community Expert
June 22, 2016

What do you mean by "pick", exactly? Do you want to display the lowest age in a text field?

omanbuxAuthor
Known Participant
June 22, 2016

hi, yes i want to display the lowest age in a text field. thanks..

try67
Community Expert
Community Expert
June 22, 2016

You can use this code as the custom calculation script of that field:

event.value = Math.min(Number(this.getField("age of account1").value), Number(this.getField("age of account2").value), Number(this.getField("age of account3").value), ...);