Set a background color on a form field

Hi all, I need to set a background color on a field of a single record form.
In grid mode I found the statement which is not applicable on a forms.
Based on some values ​​the wallpaper should be set dynamically.
Can you help me ?
Thank you

Massimo

on the OnLoad event of the form, for a campoa filed try this

$condizione = true;
if ( $condizione ) {
?>
<style>

#hidden_field_data_campoa {
 background-color: red;
}	

</style>	
<?php
}

Thanks Vincenzo for the reply.
I entered the instructions on the onload event
The field in question is called “distance”.
Mine is just an example to test the instructions.

if ( {distance} > 100 ) {
?>

#hidden_field_data_distance { background color: red; }

<?php
}

The result is that the entire row where the field is located is colored red.
The background of the field where the value is remains white, while it should be red.
I don’t know if I explained myself.
Furthermore, a window with 2 buttons “Close” and “Output” overlaps the forms. When I click on “close” it removes the set color.

Maybe I’m doing something wrong
Thank you
Massimo

Sorry, the font has been enlarged.
I don’t know for what reason.
The set instructions are as follows:
if ( {distanza} > 100 ) {
?>

#hidden_field_data_distanza { background-color: yellow; }

<?php
}

The result is that the entire row where the field is located is colored red.
The background of the field where the value is remains white, while it should be red.
I don’t know if I explained myself.
Furthermore, a window with 2 buttons “Close” and “Output” overlaps the forms. When I click on “close” it removes the set color.

Maybe I’m doing something wrong
Thank you
Massimo

Looks like you forgot the Style tags

Thanks Vincenzo, I actually wrote the instructions on SC as you indicated, substituting the name of the field, mine is called distance.
When copying and pasting from scriptcase to forum not all the lines were reported.

The result is that the entire row where the field is located is colored red.
The background of the field where the value is remains white, while it should be red.
I don’t know if I explained myself.
Furthermore, a window with 2 buttons “Close” and “Output” overlaps the forms. When I click on “close” it removes the set color.
Furthermore, the buttons for navigating between records and those for updating records are deactivated.
Thank for your support.
Massimo

create a js function that change the color a js function called sfondorosso with

$("#id_sc_field_codice").css("background-color","red");
$("#id_sc_field_codice").css("color","white");

then in the onload

$condizione = true;
if ( $condizione ) {

    sc_ajax_javascript('sfondorosso');
}
1 Like

Resolved.
To explain better, I’ll give you a practical example.
I have a field in the form called “height”.
I want the background of the field depending on the values ​​to take on a color.
Let’s simplify as much as possible:

50 yellow
< 50 green

I go to Programming – Javascript Methods.

I create a new method that I call “color_background”

Before writing the instructions, I click on the F(x) icon on the editor toolbar, to set the number of parameters. In my case 1 , I call height.

At this point I write the instructions:

if (height > 50 )
{

document.F1.height.style.color = ‘black’;
document.F1.height.style.backgroundColor = ‘#FFCC33’;
}

if (height < 50 )
{

document.F1.height.style.color = ‘black’;
document.F1.height.style.backgroundColor = ‘#66CC33’;
}

I save the script.

I go to Events and choose OnLoad

sc_ajax_javascript (‘background_color’,array({height}));

The first argument refers to the javascript script name and the second is the return parameter.

I save and run.

Surely it can be improved, but for the moment I’m happy with it.

I hope it can be useful.

Massimo