Require help in Client script

Yogita11_
Tera Contributor

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);
        } 
   
    }

}

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

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);
        } 
   }
}

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

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);
        } 
   }
}