Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Click On, Click Off

Avatar

Former Community Member

I have a text object that when clicked, it shows a circle around it. I placed the circle visable in the click event of the text object, but how do I get to to dissapear if I click on the text object again?

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

The Variable is not persisted past the life of your program ...so when the doc Ready event finishes the variable is gone. So you need some othe way to know if the circle is on or off .....why not check the presence of the circle and toggle it accordingly.

if (Circle1.presence = "visible"){

     Circle1.presence = "hidden"

} else {

     Circle1.presence = "visible"

}

Paul

View solution in original post

6 Replies

Avatar

Level 6

Use an "if" "else" statement.

Post the code you are using to make it visible and we can add the "else"

Avatar

Former Community Member

Circle1.presence = "visible";

I tried adding var OnOff = "Off" in the docready event and then adding to the click event of the text object:

if (OnOff == "Off")

{

     Circle1.presence = "visible";

     OnOff = "On";

}

else

{

     Circle1. presence = "hidden";

     OnOff = "Off";

}

But this doesn't work either.

Avatar

Correct answer by
Former Community Member

The Variable is not persisted past the life of your program ...so when the doc Ready event finishes the variable is gone. So you need some othe way to know if the circle is on or off .....why not check the presence of the circle and toggle it accordingly.

if (Circle1.presence = "visible"){

     Circle1.presence = "hidden"

} else {

     Circle1.presence = "visible"

}

Paul

Avatar

Former Community Member

Worked really well. What would you suggest I do to assign a value for if the circle is visible? I need to send the value of the circled text object to the xml file that I send via email.

Avatar

Former Community Member

Then create a hidden field that will hold the on/off value and update that when you toggle the circle on off.

Paul

Avatar

Former Community Member

I was thinking there might have been another way, but it works. Thanks.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----