August 28, 2014 at 1:31 am #180902
I am adding up a bunch of inputfields and i write the value into another Inputfield.
But this is only supposed to happen if all fields are filled. So i wanted to write the result only into the Inputfield if it’s not NaN.
I have everything set up but the last part is not working =(.August 28, 2014 at 3:16 am #180906
You are not checking the sum for
NaN,you are checking it for
''(empty string). So you could replace
if (sum !=='')with
if (!isNaN(sum))and it would work.August 28, 2014 at 3:19 am #180907
Thanks alot =). The isNaN part was what i was missing i checked it via if (sum!== ‘NaN’) the empty check if for if a user deletes an input field it deletes the sum =).August 28, 2014 at 3:50 am #180909
checked it via if (sum!== ‘NaN’)
'NaN'is a string,
NaNis a number if you check it using
NaN === NaNturns out to be
falsewhich is confusing and f*cked up but we can use
isNaN()to avoid that.
However, I don’t think I would have solved it that way. Assigning NaN to a variable seems weird I think.August 28, 2014 at 4:08 am #180912
Hmm im only beginning with this kind of work, i used a diffrent kind of calculation earlier and the empty values were NaN already.
I’m always happy about input that helps me improve. Feel free !
You must be logged in to reply to this topic.