cliemt script

1__SathvikT
Tera Contributor

I need to check whether the number field has even or odd value. If it is even then I need to display the message that field has even value.

Here is my script:

function onLoad() {
//alert("You opend the boom form ");
var fieldValue=g_form.getValue('Number');
if(fieldValue % 2 === 0){
alert('The number field contains EVEN value');
}
}

 

but I am getting alert message for both even and odd values.

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi @1__SathvikT you would need onChange client script, not onload.

onload will work only for the first time when the form loads.

script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var getNumber = g_form.getValue('number');// number is the variable name
    if (getNumber % 2 === 0) {
        // Number is even
        alert("Number is even.");
    } else {
        // Number is odd
        alert("Number is odd.");
    }

}
Regards
Harish

View solution in original post

1 REPLY 1

Harish KM
Kilo Patron
Kilo Patron

Hi @1__SathvikT you would need onChange client script, not onload.

onload will work only for the first time when the form loads.

script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var getNumber = g_form.getValue('number');// number is the variable name
    if (getNumber % 2 === 0) {
        // Number is even
        alert("Number is even.");
    } else {
        // Number is odd
        alert("Number is odd.");
    }

}
Regards
Harish