Accented characters in variables

Community Beginner ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

I'm doing a Spanish language form that displays a list of countries in a drop-down:

Seleccione el País

Colombia

Costa Rica

México

Panamá

Perú

The country name is is used to display different options. This worked as expected when the list of country names was in the dropdown validation box. But then I had to move the validation to a document-level script and now the validation doesn't work on any variable that has an accent in it. (Only Colombia and Costa Rica work as expected). So I added the following to the dropdown validation to try passing unaccented values to the document-level script:

var dropdown = event.value;

if (dropdown == "Seleccione el País"){

var resetDropdown = "Seleccione el Pais";

}else if (dropdown == "Colombia"){

var resetDropdown = "Colombia";

}else if (dropdown == "Costa Rica"){

var resetDropdown = "Costa Rica";

}else if (dropdown == "Panamá"){

var resetDropdown = "Panama";

}else if (dropdown == "Perú"){

var resetDropdown = "Peru";

}else{

var resetDropdown = "Mexico";

}

SetCountry(resetDropdown);

But the accents seem invisible to Acrobat Javascript. Accented dropdown names are not set as unaccented variable values, so Mexico becomes the variable value for the accented name.

In HTML JavaScript, I can set the value and the display text independently, but I can't see any way of doing that in Acrobat. Thanks for any ideas or hints.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

188

Likes

translate

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 1 Correct Answer

Most Valuable Participant , Dec 15, 2018 Dec 15, 2018
Go back to your code in Notepad++ and click on Encoding - Convert to ANSI.Then copy the code back to the field and it will work just fine...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

I think your issue is in how the names are being moved about. The Accented characters are part of the extended ASCII set, which is called ANSI.

Acrobat JavaScript is quite literally no different than HTML JavaScript, and both handle these characters just fine, so your issue is not with JavaScript. I just tried it and I can set the names manually through the dropdown properties dialog, or with JavaScript and the accents both display and work in a validation script.

But there are two different ways in which these could be getting screwed up, outside of scripting.  The most common issue with non-standard ASCII characters is that they are not properly supported in some editing tools. If you copied and pasted from such a tool the accented ANSI characters might have been substituted with ASCII equivalents.  The second issue is that many word processing tools use UNICODE versions of these characters rather than the ANSI codes. So if you copied and pasted from a word processing tool the accented character might have been replaced. In such a case the JavaScript comparison might fail because the Unicode character code would not match the ANSI character code.

Can you post a demo form that just contains the form fields and code that have this problem. I'd be happy to look it over.

Yuu can find more information on programming dropdowns in Acrobat and PDF here:

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

https://acrobatusers.com/tutorials/list_and_combo_in_lc

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

Likes

translate

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 Beginner ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

Thanks for your speedy reply. I'm a programmer and am using Notepad++ for code editing in Windows.

Here's a link to the version using the validation script attached to the dropdown: https://1drv.ms/b/s!AuMdOB79OSNji3Wb-T_-fjH3QVyE

Here's the version where the dropdown is passing the country name to the document script and failing: Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.

If you view these files in a browser, all layers will be visible. I'm developing this in Acrobat X, but the users are on Reader DC.

Likes

translate

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 ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

Go back to your code in Notepad++ and click on Encoding - Convert to ANSI.

Then copy the code back to the field and it will work just fine...

Likes

translate

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 ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

By the way, it is possible to have one value as the display value of an item in a drop-down field and another as its "internal" value.

Simply use the Export Value option in the Properties dialog to do it. So, for example, you can use "MX" for "México" and then use that value in your code.

Likes

translate

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 Beginner ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

Thanks, I did try that, but once the dropdown has been programmed, selecting options in the Dropdown Properties dialog runs the JavaScript instead of allowing you to set the  options.

Likes

translate

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 ,
Dec 16, 2018 Dec 16, 2018

Copy link to clipboard

Copied

Disable the code, edit the options, then enable it again.

Likes

translate

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 Beginner ,
Dec 16, 2018 Dec 16, 2018

Copy link to clipboard

Copied

Thanks for you help! I would have marked all 3 as correct if I could.

Likes

translate

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