- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 06:23 AM
Hello All,
I'm trying an addition script for one of my requirements. The script below automatically adds the previous and new values when the user enters "+integer_value" . However, when a user enters + and nothing, it saves the value "NaN". I attempted to stop this by using the if condition when the total sum is "NaN" then do not update. However, it does not identify the "NaN" and it always go in the script.
Is anyone dying?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var amount = newValue.indexOf("+");
if (amount != '-1') {
var total_length = newValue.toString();
var last_idex = total_length.length;
var additioan = newValue.slice(amount + 1, last_idex);
var convert = parseFloat(additioan, 10);
var previous_amount = parseFloat(oldValue, 10);
var Total_amount = parseFloat(convert) + parseFloat(previous_amount);
if (Total_amount != "NaN") {
g_form.setValue('u_ec_defense_counsel_fees_string_field', Total_amount);
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 06:49 AM
It looks like you could only run the rest of the script if newValue != +
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue != '+') {
var amount = newValue.indexOf("+");
if (amount != '-1') {
var total_length = newValue.toString();
var last_idex = total_length.length;
var additioan = newValue.slice(amount + 1, last_idex);
var convert = parseFloat(additioan, 10);
var previous_amount = parseFloat(oldValue, 10);
var Total_amount = parseFloat(convert) + parseFloat(previous_amount);
g_form.setValue('u_ec_defense_counsel_fees_string_field', Total_amount);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 06:49 AM
It looks like you could only run the rest of the script if newValue != +
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue != '+') {
var amount = newValue.indexOf("+");
if (amount != '-1') {
var total_length = newValue.toString();
var last_idex = total_length.length;
var additioan = newValue.slice(amount + 1, last_idex);
var convert = parseFloat(additioan, 10);
var previous_amount = parseFloat(oldValue, 10);
var Total_amount = parseFloat(convert) + parseFloat(previous_amount);
g_form.setValue('u_ec_defense_counsel_fees_string_field', Total_amount);
}
}
}