This topic is locked
[SOLVED]

 Font color in Jscript

3/22/2020 11:28:09 PM
PHPRunner General questions
M
Mark Kramer author

I'm trying to change the color of a total field on an Add screen. I use the Jscript onload event and everything works fine except I cannot get the color to change based on the value.
Here is part my code:
var gtotal = (Number(va1))+(Number(va2))+(Number(va3))+(Number(va4))+(Number(va5))+ (Number(va6))+ (Number(va7))+ (Number(va8))+ (Number(va9))+ (Number(va10))+ (Number(va11))+ (Number(va12))+ (Number(va13))+ (Number(va14))+(Number(va15))+ (Number(va16))+ (Number(va17))+ (Number(va18))+ (Number(va19))+ (Number(va20));

ctrlTotal.setValue(gtotal) ; // adds total points from Var Va1-20
if (ctrlTotal.getValue() >79) { pf.setValue("Pass" );
}

else

{
pf.setValue("Fail");
That part works great but I would like to have "Pass" turn the font Green and abd "Fail" turn it Red. I've tried various things but nothing seems to work. Any ideas or insperation would be great. I have already looked at the conditional formatting but it is in PHP and I need this to to be in Jscript since it changes on the fly with the value change.
Thanks in advanced

K
keithh0427 3/22/2020

Have you tried something like:
document.getElementById("myElement").style.color = "#ff0000";

M
Mark Kramer author 3/23/2020



Have you tried something like:
document.getElementById("myElement").style.color = "#ff0000";


Nope... I will give it a try... Thanks

M
Mark Kramer author 3/23/2020



Nope... I will give it a try... Thanks


Well no luck. It could be that the placement in the code is wrong but it is not showing any errors when I check it nor with the f12 in the browser. It should be so simple...just can't seem to solve it.

woodey2002 3/23/2020

Have a look here,
https://asprunner.com/forums/topic/26742-conditionally-change-font-colour-on-addedit-page-control/pagep88830&#entry88830
I use .addStyle('background: Orange;'); to adjust the background colour if any good to you
Cheers,

James

M
Mark Kramer author 3/23/2020



Have a look here,
https://asprunner.com/forums/topic/26742-conditionally-change-font-colour-on-addedit-page-control/pagep88830&#entry88830
I use .addStyle('background: Orange;'); to adjust the background colour if any good to you
Cheers,

James


James,
That did the trick! Thank you !!
var gtotal = (Number(va1))+(Number(va2))+(Number(va3))+(Number(va4))+(Number(va5))+ (Number(va6))+ (Number(va7))+ (Number(va8))+ (Number(va9))+ (Number(va10))+ (Number(va11))+ (Number(va12))+ (Number(va13))+ (Number(va14))+(Number(va15))+ (Number(va16))+ (Number(va17))+ (Number(va18))+ (Number(va19))+ (Number(va20));

ctrlTotal.setValue(gtotal) ; // adds total points from Var Va1-20
var ctrl = Runner.getControl(pageid, 'Pass/Fail');
if (ctrlTotal.getValue() >79)
{ pf.setValue("Pass" );

pf.addStyle('color: green;'

}

else

{
pf.setValue("Fail");

pf.addStyle('color: red;');