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

How to check string in java scripts for pdf forms

Community Beginner ,
Jul 05, 2018 Jul 05, 2018

Hello, my question is how to check one string in one field for example:
if in fill_20 the string is "Sofia" or SOFIA or sOfia or all combinations with lowercase letters and uppercase letters and so..
If fill_20 is with content=Sofia and all combination with lowercase and  uppercase letters then in fill_30 write value 100 if the string is different than Sofia then in fill_30 write 80?

TOPICS
Acrobat SDK and JavaScript , Windows
4.9K
Translate
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 ,
Jul 09, 2018 Jul 09, 2018

The first two conditions will verify if the text is EXACTLY "София" (irrelevant of upper/lower-case letters). The third will will check if it is anywhere within the string (also case-insensitive). So if you want to allow for other characters (like a space or other text) then use only the third if-statement.

Translate
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 ,
Jul 09, 2018 Jul 09, 2018

In Adobe Acrobat DC you can use:

if ( testString.trim().toUpperCase() == "СОФИЯ")

Translate
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 ,
Jul 09, 2018 Jul 09, 2018

Only this IF?

if ( testString.match(/софия/i) != null )

????

Translate
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 ,
Jul 09, 2018 Jul 09, 2018

Yeah this is enought for me!!
Now really work.
Thanks!


var testString = this.getField("fill_6").valueAsString; 

if ( testString.match(/софия/i) != null )

{

event.value = 100;

}

else

{

event.value = 80;

}

Translate
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 ,
Jul 09, 2018 Jul 09, 2018

Hi tanerz18448860​,

perhaps this is also a good way for all Acrobat versions

var testString = this.getField("fill_6").valueAsString;

if ( testString.match(/\s?софия\s?/i) != null ) {

    event.value = 100;

} else {

    event.value = 80;

}

If so, have fun

Translate
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 ,
Jul 10, 2018 Jul 10, 2018

I need help and today.

Now need to check strings with country if  in field 1 the country is USA  then in field 2 write 50, in field 3 write 80.
If the country in field 1 is  Brazil then in field 2 write 40, in field 3 write 70.
If the country in field 1 is Spain then in field 2 write 35 in field 3 write 65.
And so and so.


How can I modify this to work with many checks and if's functions?

var testString = this.getField("fill_6").valueAsString;

if ( testString.match(/софия/i) != null )

{

event.value = 100;

}

else

{

event.value = 80;

}

Translate
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 ,
Jul 11, 2018 Jul 11, 2018

I successfully do it  with to much IF'S.
But how can I do it with masives?


I do it with this codes and it's work..
var testString = this.getField("Dropdown7").valueAsString;

if ( testString.match(/Япония/i) != null )

{

event.value = 5500;

}

if ( testString.match(/Австрия/i) != null )

{

event.value = 35;

}

if ( testString.match(/Австралия/i) != null )

{

event.value = 35;

}

if ( testString.match(/Азербайджан/i) != null )

{

event.value = 30;

}


I want to do it with masives:

I find this codes:

var c30 = ["Зимбабве", "Заир", "Етиопия"];

var c35 = ["Дания", "Гърция", Германия];

var x = "Зимбабве";

var rez=0;

if(c30.indexOf(x)>=0){

rez = 30;

}

if(c35.indexOf(x)>=0){

rez = 35;

}

But ho can I implement it in java script in pdf forms?

Translate
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 ,
Jul 11, 2018 Jul 11, 2018

I tried this but it doesn't work:

var c30 = ["Зимбабве", "Заир", "Етиопия"];

var c35 = ["Дания", "Гърция", Германия];

var x = "Зимбабве";

var rez=0;

if(c30.indexOf(x)>=0){

rez = 30;

{

event.value= 30;

}

}

if(c35.indexOf(x)>=0){

rez = 35;

{

event.value=35;

}

}

Translate
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 ,
Jul 11, 2018 Jul 11, 2018

It should work, but this will only be for exact matches, ie it won't work if you add a space after the string.

If you want further help you really have to start providing more exact descriptions of the issues you're having. "It doesn't work" is meaningless to us.

Translate
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 ,
Jul 11, 2018 Jul 11, 2018

Why are you using the "rez" variable if you're applying the value to event.value directly? Get rid of rez and do it directly.

Also, you need to carefully look at the curly brackets in your code and make sure that they are set up correctly.

Translate
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 ,
Jul 11, 2018 Jul 11, 2018

Okay, can you correct my code?

Translate
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 ,
Jul 11, 2018 Jul 11, 2018

Try this:

var c30 = ["Зимбабве", "Заир", "Етиопия"];

var c35 = ["Дания", "Гърция", "Германия"];

var x = "Зимбабве";

var rez = 0;

if (c30.indexOf(x)>=0){

    rez = 30;

} else if (c35.indexOf(x)>=0) {

    rez = 35;

}

event.value = rez;

Translate
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 ,
Jul 11, 2018 Jul 11, 2018

This code solve my problem:


var testString = this.getField("Dropdown7").valueAsString;

var c30 = ["Зимбабве", "Заир", "Етиопия"];

var c35 = ["Дания", "Гърция", Германия];

if(c30.indexOf(testString)>=0){

event.value=30;

}

if(c35.indexOf(testString)>=0){

event.value=35;

}

Translate
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 ,
Jul 11, 2018 Jul 11, 2018

This is not a good solution. If the text in question is not in either of the arrays then the value of the field will just stay as it was before...

Translate
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 ,
Jul 11, 2018 Jul 11, 2018
LATEST

No, it's work, user select the country from dropdown field where I define the country names.

var testString = this.getField("Dropdown7").valueAsString;

var c30 = ["Зимбабве", "Заир", "Етиопия", "Азербайджан","Албания","Армения", "Афганистан",

"Бангладеш", "Бахрейн", "Белорусия", "Великобритания", "Виетнам", "Гана","Грузия", "Други страни",

"Египет", "Естония","Индия", "Индонезия","Ирак", "Иран", "Йемен", "Йордания", "Казахстан", "Кения",

"Китай", "КНДР", "Колумбия", "Корея", "Кот д'Ивоар", "Либия", "Ливан", "Малайзия", "Мали",

"Мароко", "Мексико", "Мозамбик", "Молдова", "Монголия", "Нигерия", "Никарагуа", "Нова Зеландия",

"Обединени арабски емирства", "Пакистан", "Перу", "Саудитска Арабия", "Сингапур", "Сирия",

"Таджикистан", "Тунис", "Тюркменистан", "Турция", "Узбекистан", "Украйна", "Чили", "ЮАР"];

var c35 = ["Дания", "Гърция","Германия","Полша","Австралия / Australia", "Алжир", "Ангола",

"Аржентина / Argentina", "Белгия", "Босна", "Бразилия","Гибралтар","Израел", "Ирландия",

"Исландия", "Испания", "Италия", "Канада", "Купър", "Куба", "Кувейт", "Латвия", "Литва",

"Лихтенщайн", "Люксембург", "Македония", "Малта", "Монако","Норвегия", "Португалия",

"Румъния", "Русия", "Сан Марино", "САЩ", "Словакия", "Словения", "Унгария", "Финландия",

"Франция", "Холандия", "Швеция", "Чехия", "Югославия" ];

var c60 = ["Швейцария"];

var c5500 = ["Япония"];

if(c30.indexOf(testString)>=0)

{

event.value=30;

}

if(c35.indexOf(testString)>=0)

{

event.value=35;

}

if(c60.indexOf(testString)>=0)

{

event.value=60;

}

if(c5500.indexOf(testString)>=0)

{

event.value=5500

}

Translate
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