![]() |
Admin 7/5/2018 |
You are not saying anything about what exactly doesn't work, your calculation or the part where you trying to assign color. |
B
|
beishmc author 7/5/2018 |
You are not saying anything about what exactly doesn't work, your calculation or the part where you trying to assign color. Normally you need to step through your code to make sure there are no Javascript errors, calculations are correct and correct branch of code is executed. If everything looks correct instead of addStyle you can try jQuery's css() function: http://api.jquery.com/css/
|
![]() |
Admin 7/5/2018 |
You really need to follow troubleshooting steps in my previous post. I'm talking about calculation inside your IF statement. You need to make sure that it produces correct result, find which branch gets executed etc. |
M
|
Mark Kramer 8/2/2018 |
I have following code which calculate values on the fly: var ctrlPstanje = Runner.getControl(pageid, 'pocetno_stanje'); var ctrlZstanje = Runner.getControl(pageid, 'zavrsno_stanje'); var ctrlUkupno = Runner.getControl(pageid, 'predjeno_km'); function func() { ctrlUkupno.setValue((+ctrlZstanje.getValue()) - (+ctrlPstanje.getValue())) ; }; ctrlPstanje.on('keyup', func); ctrlZstanje.on('keyup', func); ctrlUkupno.on('keyup', func); How can i change font color of the result based on result value? I tried something like this but it doan't work: if (ctrlUkupno.setValue((+ctrlZstanje.getValue()) - (+ctrlPstanje.getValue()))<0) { ctrlUkupno.addStyle('font-size: 12px; color: red;'); } else { ctrlUkupno.addStyle('font-size: 12px; color: green;'); }
|
B
|
beishmc author 8/5/2018 |
This worked for me. Go to the "field properties" of the "calculated field name" Under "View" choose "custom" and enter code like this: if ($value > 79) { $color="green"; } else { $color="red"; } $value="<font color='$color'>$value</font>"; //$value is the calculated field. In this case if the values is greater than 79 it will be green, else it is red.
|
C
|
cristi 8/5/2018 |
I think that you need to use .css function like admin pointed out. var number1=Runner.getControl(pageid,'number1'); |
M
|
Mark Kramer 8/9/2018 |
Thank you for your answer but this is not suitable for me, i need on the fly changing colors and yours example is changing colors based on recorded value.
|