2 Replies Latest reply on Aug 30, 2017 10:36 AM by SHillaby

    Automatically adding a specific first letter to a text field

    SHillaby

      I am newish to javascript and Acrobat forms, but starting to explore how they can make form filling easier for end users. I'd like to make one of my field automatically begin with a specific letter when the user clicks in to enter text.

       

      When the user clicks in the text field, I'd like the form to already have added a capital R to the beginning of the field. The user would not be able to delete this R. They would then proceed to enter a series of 7 numbers (any numbers).

       

      Is this possible?

        • 1. Re: Automatically adding a specific first letter to a text field
          try67 MVP & Adobe Community Professional

          That's a bit tricky, but try this:

          As the field's custom Keystroke script enter this:

          if (/^R\d{0,7}$/.test(AFMergeChange(event))==false) event.rc = false;

           

          As the field's On Focus script enter this:

          if (event.target.value=="") event.target.value = "R";

           

          That means, though, that once the user enters the field and it is populated with the "R", they won't be able to clear it... I'm not sure that's desirable. If you do want them to be able to clear the field use this code as the Keystroke script:

          if (AFMergeChange(event)!="" && /^R\d{0,7}$/.test(AFMergeChange(event))==false) event.rc = false;

           

          It's possible that after you insert this code the Format option will "jump" to None and it will appear like the code has not been saved.

          This is a bug in Acrobat. Don't worry about it. The code is still there and will work.

          • 2. Re: Automatically adding a specific first letter to a text field
            SHillaby Level 1

            Thanks very much! The second keystroke script you suggested works like a charm. Saved me more hours of fruitless searching on the web.