• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

PDF Form javascript and arguments

New Here ,
Jun 18, 2021 Jun 18, 2021

Copy link to clipboard

Copied

Hello all there,

 

mayby anyone of you could help me?

 

I produce PDF forms. To take care my users did not input absolutely wrong inputs I user Javascript to check their input.

 

As an absolutely imple example:

PDF-input-Field

on focus out automaticaly a function  "test();" ist called.

 

function test() {
// some code
var xyz = ...
app.alert(xyz);
}

Same code I need to call them leaving a lot of inputfields. So I thaught, it wold be a good idea to use arguments / parameters..

 

test("der"); // call my function in field a
test("die"); // call my function in bield b

new Javascript:

function test(v) {
// some code
var xyz = v;
app.alert(xyz);
}

But this did not work in PDF.

Could anyone help me, please?

Best Wishes

Gerhard

TOPICS
JavaScript , PDF forms

Views

1.0K

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
Community Expert ,
Jun 18, 2021 Jun 18, 2021

Copy link to clipboard

Copied

Saying "it did not work" does not give us much to go on... What exactly happens? Are there any error messages in the JS Console? What's the full and exact code you're using? Could you share the file in question?

 

And as a side-note, you don't need the xyz variable. Just use the v variable directly in the alert command.

Votes

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 ,
Jun 18, 2021 Jun 18, 2021

Copy link to clipboard

Copied

if you want to re-use the same function you have to add your code as a global script under 'javascript of document' 

if you want to check the input you have to use field variables like event.value (this is waht was entered into the field)

 

function test() {
//allow the input by default (as example, default is true)
event.rc = true; 
var input = event.value;
//if no is input, alert ohno and reject the input
if (input == "no"){
    app.alert("ohno");
    event.rc = false; 
}}

 

then for each field where you want to use that function as input validation you enter:

 

test(); 

 

to run that particular line of code

Votes

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
New Here ,
Jun 20, 2021 Jun 20, 2021

Copy link to clipboard

Copied

Maybe, because of my english, my post could not unterstand. Sorry about them.

 

@try67 

Did not work was no good description.

 

I mean.

 

In javascript usualy we can crate own functions. 

In function there is a posibilty to use arguments/parameters to sent them to be worked with.

 

Example.

Function_1(abd); // call my function

 

Function_1 is called. 

Function_1 woks with argument/parameter "abd".

 

This works with javasctipt on web. 

But on PDF it seems javascript did not use "abd". It ignores them.

 

@Wardenburg 

My script exists only as global script in javascript of document.

My idea was, on focous out I call each time my script.

Example:

Field "ab" function is called test(ab);

Field "ad" function is calles test(ad);

 

Eacht time function test ist calld javascript gets value form feld ab, ad, ... works with them and writes result in field.

 

every thin I scripted works fine. Only not woks arguments/parametes are not transportet from focus out to global function.

 

That what I mean.

please support me.

THX

 

 

 

 

Votes

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
Community Expert ,
Jun 20, 2021 Jun 20, 2021

Copy link to clipboard

Copied

If you call a function like that:

 

Function_1(abd);

 

Then abd is a variable. If you want to specify it as a string you have to put it within quotes, like this:

 

Function_1("abd");

Votes

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
Community Expert ,
Jun 20, 2021 Jun 20, 2021

Copy link to clipboard

Copied

The use of functions is the same as in web browsers.

Votes

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
New Here ,
Jul 03, 2021 Jul 03, 2021

Copy link to clipboard

Copied

LATEST

Im am verry sorry not answering as early. I got conjunctivitis. I was not able to have a view abolutely not. Expecially to use a monitor. 

 

And yes. you helped very much. The missing secret was using quotes. Thats all. O my god. So easy. And I did not recognise ist.

 

Thank you very much.

Best wishes

 

Votes

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