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

Javascript return Value based on selection in Combobox

New Here ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

Hi all,

based on the selection that the user has to make in a combo box I want a value to be written into another field, I tried the following code but it does not work:

----

var Land = this.getField("combo1").value;

 

if (Land == "Afghanistan") {
event.value = 20;
}
if (Land == "Ägypten"){
event.value = 28;
}
if (Land == "Äthiopien"){
event.value = 26;
}

----

Any hints why?

 

Kind regards

 

Matthias

ex nihil nihilo fit
TOPICS
Acrobat SDK and JavaScript

Views

1.2K

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 ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

Where did you put this script? Is it in a calculation script on the field you want to display the value?

What is happening?

Are any errors reported in the Console Window?

 

You're code should work, however, the "if" structure should be setup differently.

You'll find a tutorial on the Console Window here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

And this is an article on using the "if"

https://www.acrobatusers.com/tutorials/conditional-execution/

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

Hello Thom,

I have put the script in the user defined calculation field of a text field which i formated as as number. The script is not woking, no matter which format i use. It does not show any failures or errors, it just does not work. Any ideas?

 

Anmerkung 2020-04-14 211627.png

 

Kind regards

 

Matthias

ex nihil nihilo fit

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 ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

Yes, First remove all formatting, you don't know if it is interfering with the calculation, so it's best to not use any formatting until you have the calculation working.

The field is showing a value "20,00", so something is happening. Somehow the first "if" condition is satisfied. 

 

Some things to consider.

1) If the items in the list have export values, then your code will not work.

2) If  the "Commit Selected Values Immediattely" option is not checked, then the calculation will only run when you click off of the dropdown. So make sure this is checked. 

 

And finally, did you watch the console window tutorial?  If none of the things I've covered so far help, then you need to add a "console.println" into the code to see exactly what values are returned from a list selection.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Apr 15, 2020 Apr 15, 2020

Copy link to clipboard

Copied

Dear Thom,

the tips above are really helpful, especially the console window video is very informative! I got my script running in part now, my code currently looks like this:

 

---

var Land = this.getField("combo1").value;

if ( Land == "Afghanistan" ) {
event.value = 20 ;
}
else if ( Land == "Ägypten" ) {
event.value = 28 ;
}
else if ( Land == "Äthiopien" ) {
event.value = 26 ;
}
else if ( Land == "Albanien" ) {
event.value = 20 ;
}
else if ( Land == "Algerien" ) {
event.value = 34 ;
}
else if ( Land == "Andorra" ) {
event.value = 23 ;
}
else if ( Land == "Angola" ) {
event.value = 35 ;
}
else if ( Land == "Äquatorialguinea" ) {
event.value = 24 ;
}
else if ( Land == "Argentinien" ) {
event.value = 24 ;
}
else if ( Land == "Armenien" ) {
event.value = 16 ;
}
else if ( Land == "Aserbaidschan" ) {
event.value = 20 ;
}
else if ( Land == "Australien (Canberra)" ) {
event.value = 34 ;
}
else if ( Land == "Australien (Sydney)" ) {
event.value = 45 ;
}
else if ( Land == "Australien (Rest)" ) {
event.value = 34 ;
}
else if ( Land == "Bahrain" ) {
event.value = 30 ;
}
else if ( Land == "Brunei" ) {
event.value = 35 ;
}
else {(event.value = 0);
}

 

----

it is working except for the countries that have an "umlaut" in their names (Like Ä or Ü...) what do I have to do to make them work as well? 

 

Kind regards

 

Matthias

ex nihil nihilo fit

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 ,
Apr 15, 2020 Apr 15, 2020

Copy link to clipboard

Copied

Hi Thom,

I figured that I have to mask the Umlaute by using Unicode-Escapes like using "\u00C4gypten" instead of "Ägypten". I replaced all of them in my script but is there a more convenient/easy way?

 

Kind regards

 

Matthias

ex nihil nihilo fit

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 ,
Apr 16, 2020 Apr 16, 2020

Copy link to clipboard

Copied

LATEST

Interesting. I haven't had this issue with Umlauts and other Euro characters because they are part of the ANSI character set. Notice your unicode prefix is "00".  This could be an issue with how the names are entered or pasted into the script editor. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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