Changing color of text dynamically - Forum

Forum Navigation
You need to log in to create posts and topics.

Changing color of text dynamically

Hi All,

Been loving VisualNeo Web the more i tried to push myself to work on all possibilities. Is there a way to change the text from say, a paragraph tool, to specific color dynamically through style or something to that extent? For example, the paragraph may show some texts. And if certain phrase in the text has the word "Apple", the "Apple" text would be changed to Red color. If word is "Banana" then the "banana" text would be in yellow. Otherwise, the rest of the text color are default to black.

Any advice is appreciated. Thanks!

Hi @ronnie,

Please, try this:

GetObjectHTML "Paragraph1" [myText]
SetVar [word] "apple"
StrReplace "[myText]" "[word]" "<span style='color:red'>[word]</span>" [myText] ""
SetObjectHTML "Paragraph1" "[myText]"

In the (soon to be released) new version there will two new commands: GetObjectText and SetObjectText to get and set the text content without HTML tags.

Better than this, you can add a CSS class in Project > Properties > Styles like this one:

.coloredWord{
   color:red;
   font-weight:bold;
}

And then use this code:

GetObjectHTML "Paragraph1" [myText]
SetVar [word] "apple"
StrReplace "[myText]" "[word]" "<span class='coloredWord'>[word]</span>" [myText] ""
SetObjectHTML "Paragraph1" "[myText]"

Sample app attached.
Regards.

Uploaded files:
  • You need to login to have access to uploads.
asmat has reacted to this post.
asmat

Hi @luishp

Great. Guess I'll wait for next release to test out... thanks again1

Regards, Ronnie