How to add integer fields?

thisismichaelb
Tera Contributor

This seems like it should be simple...

 

I have an onChange client script running when one one of my fields changes, and for some reason, the integer field will only accept numbers up to 999.   It rounds 1,000 down to 1.   Not sure if my code is wrong, or there is something I am not aware of.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
     if (isLoading || newValue == '') {
           return;
     }


     //adds all estimates together and puts them into the est. total field
   var req = parseInt(g_form.getValue('u_act__requirements'),10);
   var des = parseInt(g_form.getValue('u_act__design'),10);
   var dev = parseInt(g_form.getValue('u_act__dev_config'),10);
   var itt = parseInt(g_form.getValue('u_act_it_test'),10);

   var newtotal = req + des + dev + itt;


   g_form.setValue('u_act__total', newtotal);
     
}
}}

 

If I enter 1-999 in the u_act_xxx fields, it works with no issues.   As soon as you enter 1000 or anything over 1000, it mucks things up.

 

Any suggestions?

1 ACCEPTED SOLUTION

geoffcox
Giga Guru

The parseInt command stops processing at the comma. On the server side, you can use .getXMLValue() to get the number without a comma. But on the client side, one solution is to add the attribute "format=none" on the dictionary entry for that field. This will stop the comma from being displayed, and thus read by the client script.


View solution in original post

8 REPLIES 8

Uncle Rob
Kilo Patron

I don't suppose you have to declare the variable "newtotal" to be a type of integer, do you?


Same result using this.  



var newtotal = 0;


newtotal = req + des + dev + itt;


Any particular reason you're using the radix parameter?


Uncle Rob
Kilo Patron

After you define each of those parseint variables, you could post an alert so you can be sure you're not getting any NaNs.   But I don't know why you'd get a NaN for >999 numbers and not for <999