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
6.2K
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