0

I keep getting NaN Value in the the following fields:

  • grossAmount
  • netAmount
  • retainedAmount

Here is my Jquery Code:

var $form = $('form.{/literal}{$form.formClass}{literal}');

$('input:text', $form).click( function() {
  var grossProc = $('#custom_274_-1', $form).val(0.3);
  var netproc = $('#custom_275_-1', $form).val(0.5);
  var loanSize = $('#custom_228_-1', $form).val(10000);
  var grossAmount = console.log(parseFloat($('#custom_241_-1', $form).val(loanSize*grossProc)));
  var netAmount = $('#custom_240_-1', $form).val(loanSize*netproc);
  var totalamountretained = grossAmount - netAmount;
  var retainedAmount = $('#custom_239_-1', $form).val(totalamountretained);
  var totalAmount = $('#total_amount', $form).val(netAmount);

});

Thanks in advance

2
  • Add some basic debugging or step-through to see what your actual values are: console.log(grossProc, netProc, loadSize) Commented Nov 14, 2019 at 17:14
  • Hi Mate, i've got the debug in the console and when i look at Value it just shows Nan where can i see what its trying to parse Commented Nov 14, 2019 at 17:23

3 Answers 3

2

.val(value) returns the jquery object(s) that it's applied to, for chaining, so:

var grossProc = $("#id").val(0.3);

is the same as

var grossProc = $("#id");
grossProc.val(0.3);

and you could do:

$("#id").val(0.3).hide();

You need to change this to:

var grossProc = $("#id").val(0.3).val();
Sign up to request clarification or add additional context in comments.

3 Comments

Hi mate thanks for your reply! i updated the question as i saw i wasnt clearly about what fields where coming up as Nan
No, the variables loanSize and grossProc are jquery objects, not numbers because of how you are setting grossProc = $("#id"). So it's going wrong before you see it going wrong - ie you're looking in the wrong place. parseFloat($("#id") * $("#id") will clearly by NaN. Just add .val() after every .val(val) call and you'll be ok.
No worries, glad you got it sorted. It's easy to look at where the error is occurring (parseFloat)
0

I think your grossAmount value was "" and when you try to parseFloat(grossAmount) it returns NaN and other variables using grossAmount also returns NaN while doing any opterations.

1 Comment

use parsefloat only if value !=="" && !isNaN(value)
0

you are assigning object to the variable, it should be like this

var grossAmount = parseFloat(loanSize*grossProc);

$('#custom_241_-1', $form).val(grossAmount);

3 Comments

As per my answer, loanSize and grossProc are also objects, not numbers.
you are using parseFloat on object
Same issue i think the issue is that .val(0.3) is not setting the value as a integer maybe...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.