Execute a JavaScript when a user writes something in an <input> field

Explorer ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

Hi, I need a js code for acrobate pro dc to display next action only when the user writes something in text field.

Thanks

 

 

TOPICS
Acrobat

Views

198

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

correct answers 6 Correct Answers

Participant , Feb 15, 2021 Feb 15, 2021
Maybe:var xx=this.getField("xx");If (xx.value != "") {your code} run this script on focus off event

Likes

Translate

Translate
Most Valuable Participant , Feb 15, 2021 Feb 15, 2021
As the custom validation script of the field use this: if (event.value) { // place your code here }

Likes

Translate

Translate
Most Valuable Participant , Feb 19, 2021 Feb 19, 2021
To do that you would need to use the Keystroke event. It's possible, but more complicated. And you need to provide a more detailed description of how you want it to work...

Likes

Translate

Translate
Participant , Feb 19, 2021 Feb 19, 2021
I have a similar action in my pdf. It counts points from checkboxes.You can check how many characters have been entered.Maybe it will help you.[Polish version of Acobat DC]

Likes

Translate

Translate
Participant , Feb 19, 2021 Feb 19, 2021
script in mouse exit event. if (this.getField("xx").value.length >= 1) { app.alert("out: " + this.getField("xx").value + " :-)"); } to display the current value, unfortunately you have to confirm the entry with the "enter" key. then you just need to move the mouse outside the frame and the script will run

Likes

Translate

Translate
Participant , Feb 19, 2021 Feb 19, 2021
for a joke: mouse exit event changes the string: test ONE / test TWO, and each character entered increases the frame "NextTabField". Space resets its dimensions to the initial this time the construcion if(even.value) {...} was used in the custom Format field

Likes

Translate

Translate
Participant ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

Maybe:

var xx=this.getField("xx");

If (xx.value != "") {your code}

 

run this script on focus off event

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
Most Valuable Participant ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

As the custom validation script of the field use this:

 

if (event.value) {

// place your code here

}

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
Explorer ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

This code work perfectly but it´s possible to display the next action for example after 10 characters? right now the action is displayed when they write and click out of the text 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
Most Valuable Participant ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

To do that you would need to use the Keystroke event. It's possible, but more complicated. And you need to provide a more detailed description of how you want it to work...

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
Explorer ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

Thanks once again for all the help that you provide! I will keep the code as your above suggestion, if the user must click outside the frame so be it, tx!

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 ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

I have a similar action in my pdf. It counts points from checkboxes.

You can check how many characters have been entered.

Maybe it will help you.

[Polish version of Acobat DC]

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 ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

the given solution will probably not be useful to you. requires confirmation (enter) or clicking outside the frame 😞

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
Explorer ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

Thanks a lot for your help regarding this issue, I think I will keep it simple and let the user click outside the frame to run the next action, tx for your suggestion! 

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 ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

script in mouse exit event.

 

if (this.getField("xx").value.length >= 1) { app.alert("out: " + this.getField("xx").value + " :-)"); }

 

to display the current value, unfortunately you have to confirm the entry with the "enter" key. then you just need to move the mouse outside the frame and the script will run

 

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 ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

Caution.
the Mouse Exit event is sensitive to mouse movement; if the frame is small, it is easy with the mouse cursor to accidentally move out of the frame, which will run the 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
Participant ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

look hier:

Krzysztof_OciecG_0-1613756461653.png

and script:

if (event.willCommit) {
/*
app.alert(":-)");
*/

this.resetForm([event.target.name]); // Reset field to lose focus

this.getField("YourNextField").value = event.value;

}

 

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 ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

Od course, any your script can follow the event.willcommit

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 ,
Feb 19, 2021 Feb 19, 2021

Copy link to clipboard

Copied

for a joke: mouse exit event changes the string: test ONE / test TWO, and each character entered increases the frame "NextTabField". Space resets its dimensions to the initial 😉

this time the construcion if(even.value) {...} was used in the custom Format 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
Explorer ,
Feb 22, 2021 Feb 22, 2021

Copy link to clipboard

Copied

LATEST

really nice feedback and option Krzysztof 🙂 tx a lote 

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