Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
In Adobe Acrobat DC you can use:
if ( testString.trim().toUpperCase() == "СОФИЯ")
Copy link to clipboard
Copied
Only this IF?
if ( testString.match(/софия/i) != null )
????
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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;
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Okay, can you correct my code?
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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
}