Copy link to clipboard
Copied
I'm relatively new to using Adobe Javascript, so having troubles with this simple routine and can't figure out what I'm doing wrong. Can anyone comment on this sample code? The first test works and turns the target Red but it fails the second not equal test to turn the field yellow????
var f = this.getField("word").value; {
if (f == "hello")
event.target.fillColor = color.red;}
var f = this.getField("pswrd").value; {
if (f != "hello")
event.target.fillColor = color.yellow;
}
}
I know there it is probalby easier to use an If-Else statement but I couldn't get that to work either, so backed off to doing each step separately. Thanks for any help you can give
Lew
Copy link to clipboard
Copied
Sorry field name in 4th line should be "word" not "pswrd"
Copy link to clipboard
Copied
Hi @lewisk67442759 ,
You did not tell which application you are trying to code against please provide that information so that i can move the discussion to the relevant forum for better help. Now, looking at your code it seems you are trying to make the field color red in case the word entered is red and yellow otherwise, if it is so try the following
var f = this.getField("word").value;
if (f == "hello")
{
event.target.fillColor = color.red;
}
else
{
event.target.fillColor = color.yellow;
}
Some pointers for you, the braces are needed just to enclose the statements inside the if/else clause, so I have removed the unrequired and misplaced braces. The second condition != "hello" can be implicitly implied by using an else statement, if you have some other conditions you can use the else if clause.
See the following article for some examples for understanding this better
https://www.w3schools.com/js/js_if_else.asp
-Manan