- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 02:59 PM
Hello -
I am working on an OnLoad client script that checks a currency field, and if it is the default of '0.00' I want to set the background color of the field on the form to red. I have checked around community and found some examples and based on that, I have this script, however it is not working. I was wondering if anyone could provide some guidance on this. I realize that I can use a Field Style, but I only want the background to be red if there hasn't been a value entered in there, so anything other than 0.00 in the currency field.
function onLoad() {
var element = g_form.getElement('base_rent_per_month');
var value = g_form.getValue('base_rent_per_month');
if (value == 'USD;0.00') {
element.style.backgroundColor = "red";
}
}
I have also tried different value combinations like: '0' '0.00' '' 'USD;0'
Thanks!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 05:55 PM
Appreciated that you have pointed towards one of the possible cons of using hardcoded value which might change for different languages.
I hope so that g_form.getDecimalValue() pointed by you in your answer, will also work for values like you have specified "USD;0,00", or for any other possible value which does not contain dot(.) to distinguish decimal part of a number.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var display = g_form.getControl('<your_table_name>.<your_field_name>.display');
var currency= g_form.getControl('<your_table_name>.<your_field_name>.currency');
if(g_form.getDecimalValue('<your_field_name>') == 0){
display.style.background = 'red';
currency.style.background = 'red';
}
else{
display.style.background = 'white';
currency.style.background = 'white';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 05:55 PM
Appreciated that you have pointed towards one of the possible cons of using hardcoded value which might change for different languages.
I hope so that g_form.getDecimalValue() pointed by you in your answer, will also work for values like you have specified "USD;0,00", or for any other possible value which does not contain dot(.) to distinguish decimal part of a number.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var display = g_form.getControl('<your_table_name>.<your_field_name>.display');
var currency= g_form.getControl('<your_table_name>.<your_field_name>.currency');
if(g_form.getDecimalValue('<your_field_name>') == 0){
display.style.background = 'red';
currency.style.background = 'red';
}
else{
display.style.background = 'white';
currency.style.background = 'white';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2022 06:51 AM
Thank you all for the responses and input. The OnChange client script provided by
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2022 06:12 AM
I hope so that g_form.getDecimalValue() pointed by you in your answer, will also work for values like you have specified "USD;0,00", or for any other possible value which does not contain dot(.)
It does, that is why I suggested it 🙂