Change Background-Color in a Form-Field

Hello!
Now that I’ve searched again and tried it a dozen times - here is the correct way.

Create a blank application. Lets call it “colortest”.

Create 1 Num-Field “num1” (integer), 1 Text-Field “text1”.

Create a “onLoad” event
(For this test we don’t need Ajax Events).

=======
[field] = “text1”;
[color] = “red”; // Example

if({num1} == 1)
{
[color] = ‘green’;
}
else {
[color] = ‘red’;
}

sc_ajax_javascript(‘setcolor’,array([field],[color]));

=======

Save this event.

And now comes the important point that I always keep forgetting:
We want to set global variables in brackets here - we need them to pass to JS.

We therefore switch to the Application tab
Under Global Variable, we now have to select Type “out” for these variables.
Otherwise they will not be processed!

And now we need a JS-Method called “setcolor”:

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

=======

And we still need to add an attribute - in this case two. in the correct order:
“field” and “color”.

That’s it!

Start, enter 1 and click OK!

2 Likes

Excellent solution - it works very well on single row SC forms.
Regret it does not work on multiple rows.
Does the java also need a row identifier, and if so does any body know how to do that.

🚀 Scriptcase 9.12 is now available! Check out the new features here 👉🚀 Next Monday (02/24), Scriptcase 9.12 will be released! Check out the new features before anyone else 👉