Skip to main content

Forums

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #180902
    Kingslayer
    Participant

    Hello Guys,
    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 =(.

    http://codepen.io/Kingslayer/pen/kLFDf

    #180906
    Chromawoods
    Participant

    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.

    #180907
    Kingslayer
    Participant

    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 =).

    #180909
    Chromawoods
    Participant

    checked it via if (sum!== ‘NaN’)

    'NaN' is a string, NaN is a number if you check it using typeof :/. Also, NaN === NaN turns out to be false which 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.

    #180912
    Kingslayer
    Participant

    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 !

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.