How Can I Pass A Hex Code For Background Colour Via A Query Parameter?

I want to pass a query parameter to a page to specify hex colour code to be used as the background colour for various items on the page. It is a booking form I want my users to be able to customise.

So the page will be called as something like:

form.php?bg=f8f8f8

Having passed the query parameter, what would be the best way to apply it as the background colour to an element? :thinking:

Should I just apply an inline style? I’m experimenting with that as a dmx-style parameter but it isn’t working so well…

Is dmx-style supported?

This doesn’t work:
(just using a variable for now rather than a query param):

<dmx-value id="bg_color" dmx-bind:value="'ff0000'"></dmx-value>
<div class="container p-3 b_right2 rc_20 mt-5 container_section shadow" id="c_contact" dmx-show="form_mode.value=='event'" dmx-style="'background-color:#'+bg_color.value+' !important;'">

But I know the inline style itself is working:

<dmx-value id="bg_color" dmx-bind:value="'ff0000'"></dmx-value>
<div class="container p-3 b_right2 rc_20 mt-5 container_section shadow" id="c_contact" dmx-show="form_mode.value=='event'" style="background-color:#ff0000 !important;">

dmx-style should work, eg:
dmx-style:background-color="'#'+query.bg"

The option is under dynamic attributes:

Or you could include the ‘#’ symbol in the URL parameter, in which you’ll need to encode it, eg:
form.php?bg=%23f8f8f8

Antony,
why not use the UI when you don’t know what the syntax is instead of typing random things as expressions?

Screenshot 2021-10-01 at 19.03.55

I didn’t realise it was in the UI…

I typed the style="" first to be sure the style itself would work…

Then I thought “Oh, maybe I can dmx-style it…”

So I typed what I put in the post…

Then I look in the menus and Style didn’t appear - maybe because I’d already used it?

We all think and go about things in different ways…

And as you know, the menus have many problems when you build a big app, I have discussed them many times on here, so you just start to move away from using them and starting off with code.

I hope you can understand and respect my thought process and not end up concluding that you think I am stupid…

I can assure you I am not… I am just very individual and unique! :innocent:

No, i am not aware of that.

An useful advice here: when you don't know the correct syntax for adding anything in your code then use the UI.

I have posted many times about it... it needs the Data Bindings window to be an Expression Builder to be really useful and cutting/pasting/editing the code is so much easier when you have 40k lines of code and a gazillion different html elements to remember the names of and search for...

I did, but because of the code I already had there, the option had disappeared from the menu so I didn't realise it should be there...

But hey, the community is here to help us however we approach the problem, so thanks to you and @TomD for the solution... I have it working really nicely! :slight_smile: