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
Hi,
The easiest way to manage this would be to use toLowerCase() or toUpperCase(), before your comparison, written out in fulll to make it easy to follow it would look something like :
var testString = this.getField("fill_20").valueAsString;
if ( testString.toUpperCase() == "SOFIA")
{
this.getField("fill_30").value = 100;
}
else
{
this.getField("fill_30").value = 30;
}
Hope this helps
Malcolm
[Edited to correct typo]
Copy link to clipboard
Copied
I tried this but nothing is happened.
var testString = this.getFIeld("fill_6").valueAsString;
if ( testString.toUpperCase() == "SOFIA")
{
this.getField("fill_13").value = 100;
}
else
{
this.getField("fill_13").value = 80;
}
If I put SOFIA in fill_6 then write value 100 in fill_13
If in fill_6 the string is not SOFIA then write value 80 in fill_13.
Copy link to clipboard
Copied
Change:
this.getField("fill_13").value
To:
event.value
And make sure you place the code as the custom calculation script of "fill_13".
Copy link to clipboard
Copied
var testString = this.getFIeld("fill_6").valueAsString;
if ( testString.toUpperCase() == "София")
{
event.value = 100;
}
else
{
event.value = 80;
}
Doesnt work.
Copy link to clipboard
Copied
Try
if ( testString.toUpperCase() == "СОФИЯ")
or
if ( testString.toLowerCase() == "софия")
Copy link to clipboard
Copied
var testString = this.getFIeld("fill_6").valueAsString;
if ( testString.toUpperCase() == "СОФИЯ")
{
event.value = 100;
}
else
{
event.value = 80;
}
No it doesn't work.
Copy link to clipboard
Copied
"Doesn't work" is not very helpful to us. You need to provide more details. Also, the fact that you changed the string to Cyrillic characters is quite crucial.
Copy link to clipboard
Copied
There is a subtle but important error in the first line. JavaScript is case sensitive, that is you must use capital or little letters exactly right. But you have a capital I in getFIeld.
This should be reasonably obvious from the error messages in the console, do you know how to check that?
Copy link to clipboard
Copied
What does it say in the console, exactly, please?
Copy link to clipboard
Copied
As Test Screen Name said:
The code of BarlaeDC has a typo in line #1
var testString = this.getFIeld("fill_6").valueAsString;
should be
var testString = this.getField("fill_6").valueAsString;
Furthermore:
Cyrillic characters shouldn't make any difference.
Try this code in ESTK (not in Acrobat)
var testString= "СоФиЯ"; //small and capital letters
if ( testString.toUpperCase() == "СОФИЯ")
{
alert("UpperCase works")
}
else
{
alert("UpperCase doesn't work")
}
if ( testString.toLowerCase() == "софия")
{
alert("LowerCase works")
}
else
{
alert("LowerCase doesn't work")
}
Are you sure that there is no space after ?
Here is another test (also for ESTK)
var testString= "СоФиЯ "; // small and capital letters + one space
if ( testString.toUpperCase() == "СОФИЯ")
{
alert("UpperCase works")
}
else
{
alert("UpperCase doesn't work")
}
if ( testString.toLowerCase() == "софия")
{
alert("LowerCase works")
}
else
{
alert("LowerCase doesn't work")
}
if ( testString.match(/софия/i) != null )
{
alert("Regex works")
}
else
{
alert("Regex doesn't work")
}
Copy link to clipboard
Copied
Here everything is work:
The result is UpperCase works and LowerCase works.
Here :
The result is UpperCase doesn't work, LowerCase doesn't work and Regex works!
Copy link to clipboard
Copied
Regex also works for:
var testString= "СоФиЯ abc";
Copy link to clipboard
Copied
HI,
It looks like Uppercase and Lowercase if statements are working as expected, as you have added a space, the strings do not match, and therefore it would always be the else that is fired.
The regex is checking that the string contains the characters and therefore it is matching, as it should.
If you want to include the space you need to include that in the IF statements as well. something like
var testString= "СоФиЯ "; // small and capital letters + one space
if ( testString.toUpperCase() == "СОФИЯ ")
{
alert("UpperCase works")
}
else
{
alert("UpperCase doesn't work")
}
if ( testString.toLowerCase() == "софия ")
{
alert("LowerCase works")
}
else
{
alert("LowerCase doesn't work")
}
if ( testString.match(/софия/i) != null )
{
alert("Regex works")
}
else
{
alert("Regex doesn't work")
}
Or you could use a function or similar to remove any whitespace from your string before you start something like this would work.
function trim (aString)
{
return aString.replace(/(^\s*)|(\s*$)/g,"");
}
this removes whitespace from the string, allowing you to compare just the characters.
Hope this helps
Malcolm
Copy link to clipboard
Copied
Thank you but how can I implement it with all combinations of София with upper and lower case and space.
If София is in fill_20 then in fill 30 write 100 else write 80 .
Copy link to clipboard
Copied
Use something like this:
if ( testString.trim().toUpperCase() == "СОФИЯ")
Copy link to clipboard
Copied
Note that the trim method is not supported in versions of Acrobat prior to DC. It's better to define your own function, just in case.
Copy link to clipboard
Copied
Ieeeeeee!
It's work!
Thank you so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
var testString = this.getField("fill_6").valueAsString;
if ( testString.toUpperCase() == "СОФИЯ")
if ( testString.toLowerCase() == "софия")
if ( testString.match(/софия/i) != null )
{
event.value = 100;
}
else
{
event.value = 80;
}
Copy link to clipboard
Copied
Your conditions are redundant. If the first condition is true then the other two will be true by definition. They are not needed.
Copy link to clipboard
Copied
This will not detect all combinations of София with upper and lower case and space.
Copy link to clipboard
Copied
I write this script in fill_13 where is the fill where I want to put value 100 or 80.
It's work!
Copy link to clipboard
Copied
You don't need all three if clauses. Finally you only need one of them.
Copy link to clipboard
Copied
What I need?
I tested all combination with София and it's work?
Copy link to clipboard
Copied
You are right it does'nt work.
For example if I enter something different from "София" in the first time the value is 80, when I enter "София" the value is change to 100, now if I enter something different from "София" the value is not changed to 80 is 100....
Copy link to clipboard
Copied
Yes, but I want to detect the all three combinations of София with upper and lower case and space.
How can I do it?