0

I have a Adobe document that I enter the three digit social security number in 3 fields and then combine those into one field for later use further along in the document. I use the following Java script:

    `var three = this.getField("Social Security");
    function collatePreSetFieldsTo(populate){
    //always overwrite the value in populate field
    //if(populate.value==''||populate.value==null){
    var one = this.getField("SSF");
    var two = this.getField("SSM");
    var three = this.getField("SSL");
    populate.value=one.value + '-' + two.value + '-' + three.value;
    //}
}

collatePreSetFieldsTo(three);

`

This works except for the fact that if one of the numbers contain a zero at the beginning. It then drops the zero. I have tried to add to the variable statements "toString() " and "AsString" and every other thing that the internet has suggested. Nothing is working and was wondering if anyone has any suggestions on what I might be doing wrong. I am using Adobe X Pro. Thanks.

BurtG
  • 21
  • 4
  • What is being generated when first field is 0? – Void Spirit Oct 03 '18 at 20:39
  • What you are looking for is called number `padding`. I am not sure if `Adobe` JS supports this, Here is a good read. https://stackoverflow.com/questions/2998784/how-to-output-integers-with-leading-zeros-in-javascript – Zak Oct 03 '18 at 20:45
  • Tima when I enter a number like 123 05 6789 it will display as 123-5-6789 instead of 123-05-6789. Zak I tried number padding and that did not work. – BurtG Oct 03 '18 at 21:41

1 Answers1

0

The populate line should look like: populate.value=one.valueAsString + '-' + two.valueAsString + '-' + three.valueAsString;

I was putting the "AsString" in the wrong place.

BurtG
  • 21
  • 4