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

Would like to take certain actions based on a word entered into a text field

Community Beginner ,
Oct 14, 2020 Oct 14, 2020

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

Views

123

Translate

Translate

Report

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 ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

Sorry field name in 4th line should be "word" not "pswrd"

Votes

Translate

Translate

Report

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 ,
Oct 14, 2020 Oct 14, 2020

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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