Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Variable javascripts will not work properly in Reader

Avatar

Level 1

I have named the variable/script: DateNumberToDay

Essentially if you enter 1 - 31 it will change the number to 1st, 2nd, 3rd.... as in the 1st day of September....

The below script works in one of the other forms correctly but not in the this form for some reason. I even copied and retyped everything change field names etc... still not working.  Any suggestions?

Here is the script:

DateNumberToDay(oField)

(oField.rawValue == 1 | oField.rawValue == 01)

= "1st";

(oField.rawValue == 2 | oField.rawValue == 02)

= "2nd";

(oField.rawValue == 3 | oField.rawValue == 03)

= "3rd";

(oField.rawValue == 4 | oField.rawValue == 04)

= "4th";

(oField.rawValue == 5 | oField.rawValue == 05)

= "5th";

(oField.rawValue == 6 | oField.rawValue == 06)

= "6th";

(oField.rawValue == 7 | oField.rawValue == 07)

= "7th";

(oField.rawValue == 8 | oField.rawValue == 08)

= "8th";

(oField.rawValue == 9 | oField.rawValue == 09)

= "9th";

(oField.rawValue == 10)

= "10th";

(oField.rawValue == 11)

= "11th";

(oField.rawValue == 12)

= "12th";

(oField.rawValue == 13)

= "13th";

(oField.rawValue == 14)

= "14th";

(oField.rawValue == 15)

= "15th";

(oField.rawValue == 16)

= "16th";

(oField.rawValue == 17)

= "17th";

(oField.rawValue == 18)

= "18th";

(oField.rawValue == 19)

= "19th";

(oField.rawValue == 20)

= "20th";

(oField.rawValue == 21)

= "21st";

(oField.rawValue == 22)

= "22nd";

(oField.rawValue == 23)

= "23rd";

(oField.rawValue == 24)

= "24th";

(oField.rawValue == 25)

= "25th";

(oField.rawValue == 26)

= "26th";

(oField.rawValue == 27)

= "27th";

(oField.rawValue == 28)

= "28th";

(oField.rawValue == 29)

= "29th";

(oField.rawValue == 30)

= "30th";

(oField.rawValue == 31)

= "31st";

strTest;

= oField.rawValue;

myRegExp = /\b(1st|2nd|3rd|4th|5th|6th|7th|8th|9th|10th|11th|12th|13th|14th|15th|16th|17th|18th|19th|20th|21st|22nd|23rd|24th|25th|26th|27th|28th|29th|30th|31st)\b/;

matchPos1 = strTest.search(myRegExp);

(matchPos1 == -1)

,"ORDINAL NUMBER ENTRY ERROR",1);

= "";

5 Replies

Avatar

Level 4

Is this a LiveCycle Designer form?

Avatar

Level 1

Yes, this is a LiveCycle ES4 Designer form.

Avatar

Level 4

OK. I moved the question to the LiveCycle Designer forum.

Avatar

Level 4

Are you sure this JavaScript?

A line like

(oField.rawValue == 1 | oField.rawValue == 01) = "1st";

looks to me like a part of an if statement and a part of a variable assignment.

Maybe you want to reformat your code in a standard way and re-post it completly?

Avatar

Level 10

Hi,

I can't make sense of your code either, but I do use this function (stolen from the momentJS library) and which is a bit simpler.

function Ordinal(number) {

    var b = number % 10;

    var output = (Math.floor(number % 100 / 10) === 1) ? 'th' :

                (b === 1) ? 'st' :

                (b === 2) ? 'nd' :

                (b === 3) ? 'rd' : 'th';

    return number + output;

}

Just pass in the oField.rawValue not the whole field itself.

Bruce