Can I use a field in an html tag?

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • Answered
I tried this formula in a text formula field, but the background color does not change when I use the text field called Calendar Color in the html tag. I don't get any syntax errors, but the background color doesn't change.  In this example, the Calendar Color field has a value of #0040ff.

"<div style=\"color:white;background-color:[Calendar Color];\"> " &[Calendar Color]& "<div>"

Please let me know if I'm missing something to use a field in an html tag, or if that's just not possible.
Photo of Derek

Derek

  • 0 Points

Posted 3 years ago

  • 0
  • 1
Photo of Xavier Fan

Xavier Fan, Champion

  • 800 Points 500 badge 2x thumb
You were really close - you just needed to put quotes and "&" before and after [Calendar Color], so that the value in the [Calendar Color] field gets filled in.  If [Calendar Color] is inside the quotes, then the string "[Calendar Color]" gets displayed, which is not a valid background-color.

Here's the updated formula:

"<div style=\"color:white;background-color:" & [Calendar Color] & ";\"> " &[Calendar Color]& "<div>"
Photo of Jana

Jana

  • 324 Points 250 badge 2x thumb
Awesome!!  One step further....how can you add regular TEXT and a FIELD to this code?  My example:

IF ([Jury Duty Count Helper] = 0 and [JRY Form] > 0, "<div style=\"color:#D5152E;font-weight:bold; background-color:" &  [Jury Duty Doc Outstanding Duration] & ";\"> " &[Jury Duty Doc Outstanding Duration]& "<div>")

The text i would want to add would be be "Jury Duty Doc Outstanding for" prior to the field [Jury Duty Doc Outstanding Duration].

Thanks!
Photo of Derek

Derek

  • 0 Points
Thanks a lot!
Photo of Xavier Fan

Xavier Fan, Champion

  • 800 Points 500 badge 2x thumb
You're welcome!