Form field conditional formatting

Hi. i am trying to change the background color of a field of a form depending on its value. the macro ia always use for the grid does not work for forms.
i understand can be accomplished with javascipt but i know nothing about it.

i need somethnig like this:

if ({my_field} == “yes”) {

//the my_field background becomes red
}

else {

//the my_field background becomes green
}

it is ok for me in the onload event.

Thank you

You need to use javascript:

document.F1[‘id_sc_field_YOUR_FIELDNAME’].style.backgroundColor = YOURCOLOR;

thanks for your response.

-can i put this directly in the onload event ora should i create a javascript method and then call it from the onload event?

-what “is d_sc_field” ?

Thank you

You must create a javascript function. and from Onload Call this function. With:
sc_ajax_javascript(‘my_functioncolor’, array([g_mycolor]));
the variable global: [g_mycolor] if you set a param for the color of your javascript function
The prefix: “is d_sc_field” is used for SC for to name some fields.

sorry to bother you but i still can’t understand how the javascript function must be written, my bad.
So i found another post and with the webhelp i have done this:

name of the javascript function: my_functioncolor

document.F1[‘my_field’].style.backgroundColor = ‘red’; //where “my_field” is the name of the field i want to conditionally color

onload event:

if ({my_field} == “yes”) {

sc_ajax_javascript(‘my_functioncolor’);

}

does not work of course
thank you

My field must have the prefix: id_sc_field so if your field name is my_field, then it must have: id_sc_field_my_field.

in javascript function must be: document.F1[‘id_sc_field_my_field’].style.backgroundColor = ‘red’;

Here a Thread about that: http://www.scriptcase.net/forum/forum/scriptcase-7/discussion/8472-dynamically-setting-form-styles

getting closer…but …now i realize that my field stars with a number. it is called “4_stage”

so the function

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

does not work.

then i tried (for a a test) with another field that starts with a letter i.e. “side”

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

and it works…finally but not the column i am interested in…

is it possible to work with column starting with a number? i would avoid to rename the column in the db

Thanks