Form Field color

HEllo.
i have a form in which i would like to change the background and the text color depending on the value of the field.

fro the grids there is sc_field_style macro
but, what about the forms?
this macro does not apply to forms

Thanks

This is from a previous post:

With the scriptcase macro:

sc_field_color(“Field”, “Color”)

Example:
if ({value_order} > 1000)
{
sc_field_color (“value_order”, “#33FF66”);
}
else
{
sc_field_color (“value_order”, “”);
}

Thanks but i think this is meant only fro grids.
does not work no forms

“This macros its used to change/restore a grid field text color dynamically.”

You can use this on forms, this was on a previous post as well:
[TABLE=“width: 892”]
[TR]
[TD=“class: forumheader3”]Change color of a field in a normal form[/TD]
[/TR]
[TR]
[TD=“class: forumheader3”][/TD]
[TD=“class: forumheader3”] From the forum of Scriptcase by JSB

		onLoad: //or wherever you need it
		coloration();
		
		PHP Method coloration:
		
		$field = 'invoice_id';
		$color = 'red';
		if({invoice_status} == 1)
		{
		$color = 'green';
		}
		sc_ajax_javascript('set_color',array($field,$color ));
		
		Javascript Method set_color(field,color):
		
		document.F1[field].style.backgroundColor = color;
		[/TD]
	[/TR]
 [/TABLE]

sorry form bothering you again.

i need a little help since i don’t knw javascript at all.

let’ say my form is called form_a and the field in it i want to change the color to is called field_a.
how should i change the example you made before? i don’t undersantd what is document.F1 string for example

onLoad: //i need it in onload event
coloration();

PHP Method coloration:

$field = ‘field_a’;
$color = ‘green’;
if({invoice_status} == ‘pathogen’)
{
$color = ‘red’;
}
sc_ajax_javascript(‘set_color’,array($field,$color ));

Javascript Method set_color(field,color):

document.F1[field].style.backgroundColor = color;

thank yoy again

Only use this code, other is Javascript method:

From the forum of Scriptcase by JSB

onLoad: //or wherever you need it
coloration();

PHP Method coloration:

$field = ‘invoice_id’;
$color = ‘red’;
if({invoice_status} == 1)
{
$color = ‘green’;
}
sc_ajax_javascript(‘set_color’,array($field,$color ));

i will try it. Thanks

Hi, i found this post for my problem. but the variables $field and $color, was ignored in the javascript methode and is not working. if i enter in javascript mode the file and the color directly, works fine.

any idea?

Try use global variable as [field] and [color].

ok i tested this with $ [] whitout any $[’
in the event onLoad of the form
$field = ‘id_sc_field_colorexample’;
$color = {Hex};

sc_set_global($field);
sc_set_global($color);

Field_Coloration(); (php methode)

on PHP-Methode Field_Coloration
echo(‘field ‘.[field].’ color = ‘.[color].’
’); // Variables ok
sc_ajax_javascript(‘set_color’,array([field],[color]));

on Javascript-Methode
document.F1[‘id_sc_field_colorexample’].style.backgroundColor = [color];

if i do this like the example, not working!!!

here is the string that will run

document.F1[‘id_sc_field_colorexample’].style.backgroundColor = ‘red’;

how call the globals for example by document.F1[’ and now the Variable [field] or whitout ’ like [[

don’t show on color group id, is allways not configured!!

Hi, here a example of my my code:

from where you have the [g_colores]?

onLoad, {Hex} is my field with the color code

is not working

I am using colors from my database:
Try in your code:
[g_color] = ‘#FF7474’;
and in your macro: sc_ajax_javascript(‘set_color’, array([g_color]));
here is my table colors:
image

im using also a table for the colors

the field with the color code is {Hex}

onLoad
[g_color] = ‘#FF7474’;
sc_ajax_javascript(‘set_color’,array([g_color]));

Javascript-Methode
document.F1[‘id_sc_field_colorexample’].style.backgroundColor = color;

other test
JavaScript Methods
document.F1[‘id_sc_field_colorexample’].style.backgroundColor = g_color;

both are not working.

I think your function does not have parameter for color.

This is the first time that I have set up a Javascript function. I didn’t know that you had to add parameter (fx) there. Now it works.

Thank you very much!!!

How do I make it so that every single color is displayed in the selection in CalendarCategories (Select field)?