Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Selecting Specific Text within a Text Field

Participant ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

I am looking for a way (potentially using JavaScript) to have a portion of text within a field be selected upon entering a field. Below is an example:

 

Screenshot 2021-05-03 162318.jpg

My intention is for the document to increment the highest photo number currently in use by 1 (which is usually what the user will want) and place that after the user's initials. The part I need help with is to select the text of the number in case this "prediction" is wrong. This will enable the user to simply begin typing the number they want in the event that they threw away a photo or otherwise skip a number.

I am using the latest version of Acrobat Pro DC. Thank you for reading, and I appreciate any help anyone has to offer!

TOPICS
Create PDFs, PDF forms

Views

236

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

I don't believe that's possible using a script.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

What I would do instead is populate the field when the user clicks into it with the next number using the On Focus event (maybe checking it's not empty first, as to not overwrite any custom values the user entered before). This will allow the user to change the value if they wanted to, or just tab to the next field if the automatic value is correct.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Okay, I see this potentially still doing exactly what I want. For now I have a simple script putting in the user's intials with the On Focus:

if(event.target.value == ""){
    event.target.value = this.getField("Camera").value;
}

With this, the text which is input is not selected. Is there a way to have everything selected once the desired info is "typed in"?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

The only way to select the text of a field is to set focus to it, which you can do like this:

this.getField("FieldName").setFocus();

This would select the full contents of that field.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

I don't think this would work on the On Focus event, though, as the field already has the focus at that moment...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Okay, I need a way to have the text selected once the user enters the field. Let's start there. Is that possible? Can I call a doc level function that then calls setFocus() back to the field or something?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

LATEST

I don't think so. It will only work if you set the focus to another field and then back to it, but that would create an endless loop... I think you're over-complicating this. Use the initial method I described, or abandon this idea.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Then I can have the initials added to the beginning with an On Blur trigger (hopefully).

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines