Using parseInt in script but getting NaN result
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2013 06:34 AM
I am writing a script to add a simple series of form data. I am very new to scripting, but this seemed pretty straight forward. Any thoughts as to what I did wrong?
//this script calculates the total amount of departmental allocations and only allows submit if total value = 100%
function onSubmit() {
var pc1 = parseInt(g_form.getValue('variables.hr_percentage'), 10);
var pc2 = parseInt(g_form.getValue('variables.hr_percentage_2'), 10);
var pc3 = parseInt(g_form.getValue('variables.hr_percentage_3'), 10);
var pc4 = parseInt(g_form.getValue('variables.hr_percentage_4'), 10);
var pc5 = parseInt(g_form.getValue('variables.hr_percentage_5'), 10);
var pc6 = parseInt(g_form.getValue('variables.hr_percentage_6'), 10);
var tot = pc1 + pc2 + pc3 + pc4 + pc5 + pc6 ;
if(tot != '100'){
alert (tot) ;
alert('Total allocation amounts must equal 100%, please adjust the values and re-submit.');
return false;
}else{
return true;
}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2013 08:51 AM
Your example is correct. I am not sure what was going on a with my original scenario, it was obviously something else.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2013 07:46 AM
Can you please show me an example of what
looks like? Does it have % included in it?
(g_form.getValue('variables.hr_percentage')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2013 08:23 AM
Can you please show me an example of what (g_form.getValue('variables.hr_percentage') looks like? Does it have % included in it?
its a variable - single line text.
just numerical value being entered...no spaces or special characters.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2013 08:42 AM
Try adding zero like this to see if that forces the correct data type.
var tot = pc1 + pc2 + pc3 + pc4 + pc5 + pc6 + 0;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2013 08:52 AM
Mark,
I tried the +0 with the same result.
makes no sense, I am missing something basic I am sure.
next stop "jim Coyne"