Field shows NAN

shaikkhasim
Tera Contributor

Hi Team

i have calculated the sum of subjects and i used to push out the total marks in the filed of total marks but in that filed instead of total marks it shows NAN error 

 

my script is as below 

if(newValue)
{
var t=parseInt(g_form.getValue('u_telugu'));
var h=parseInt(g_form.getValue('u_hindi'));
var e=parseInt(g_form.getValue('u_english'));
var m=parseInt(g_form.getValue('u_maths'));
var s=parseInt(g_form.getValue('u_social'));
var p=parseInt(g_form.getValue('u_physics'));
var sc=parseInt(g_form.getValue('u_science'));
var k=parseInt(t+h+e+m+s+p+sc);
g_form.setValue('u_total_marks',k);
}
}

khasim
1 ACCEPTED SOLUTION

Hemant Goldar
Mega Sage
Mega Sage

Hi @shaikkhasim ,

 

Looking at the screenshot provided. I think you have set the onChange field value = Hindi.
So you're getting a NaN error on Total Mark.

 

Make sure you set the Onchange field to Social.

 

I hope it will resolve your issue.

 

Regards,

Hemant 

**Please mark my answer correct or helpful based on the impact**

View solution in original post

7 REPLIES 7

Upender Kumar
Mega Sage

try below with every variable.

var t=isNaN(parseInt(g_form.getValue('u_telugu')))?0:parseInt(g_form.getValue('u_telugu'))

Rajat_Choudhary
Tera Expert

Hi Shaikkhasim,

 

Assuming the values on your form are not of type Integer already.

From the code it is visible that you are trying to parseInt a value which is already a number. As parseInt is already done for those fields.

Syntax for parseInt. parseInt(string)

 

Can you try once to not parseInt the var k value.

var k=t+h+e+m+s+p+sc;

 

Hope this will resolve the issue.

Please mark the answer as helpful and correct.

Best Regards,

Rajat Choudhary

Hope this answers will be helpful.
Please mark the answer as helpful and correct.

Best Regards,
Rajat Choudhary

nayanawadhiya1
Kilo Sage

Hello Shaik,

It is showing you NaN because rest of the blanks are blank and you are converting blank string value as string.

Put some validation in the script like below -

var k =0:

If(g_form.getValue('u_hindi') != ''){

k += parseInt(g_form.getValue('u_hindi');

}

Hemant Goldar
Mega Sage
Mega Sage

Hi @shaikkhasim ,

 

Looking at the screenshot provided. I think you have set the onChange field value = Hindi.
So you're getting a NaN error on Total Mark.

 

Make sure you set the Onchange field to Social.

 

I hope it will resolve your issue.

 

Regards,

Hemant 

**Please mark my answer correct or helpful based on the impact**