-3

I have this JS var, followed by this if statement :

if ($('custom_t4'))
                var contratType = $('custom_t4').value === 'Nouvelle_affaire' ? 'Nouvelle Affaire' : $('custom_t4').value === 'Avenant' ? 'Avenant' : '';



if (contratType && (contratType !== 'Nouvelle Affaire' || contratType !== 'Avenant')){ }

The problem I have, is that when contratType is defined and his value is 'Nouvelle Affaire', is still enter that if.

Did I miss something ?

Nathan30
  • 689
  • 2
  • 8
  • 29
  • 1
    *'If foo isn't "bar" or isn't "baz"'* – it can't be both at once, so it'll always *not* be one or the other. In other words, that condition is *always* true. – deceze Aug 28 '17 at 09:19
  • 1
    Aside from the issue that `contratType !== 'Nouvelle Affaire' || contratType !== 'Avenant'` is always true (the part of this I marked as duplicate), you're also running into [this issue (jQuery objects are always truthy)](https://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery) **and** getting the value of the element incorrectly (jQuery objects have no `value` property; you can get the value of an `input` wrapped by a jQuery object via [`val`](http://api.jquery.com/val/)). – T.J. Crowder Aug 28 '17 at 09:20

1 Answers1

1

In Second condition OR (||) Operator is the problem. Correct Code written below

if (contratType && (contratType !== 'Nouvelle Affaire' && contratType !== 'Avenant')){ }
Ankur
  • 496
  • 1
  • 6
  • 11