IF Statement Always True
You need to use ==
or ===
for comparison instead of =
.
-
x = y
assignsy
tox
-
x == y
checks ify
andx
are loosely equal -
x === y
checks ify
andx
are equal and of the same type
So what you need to do is replacing if (hv.val = "1")
with if (hv.val == "1")
you wrote
if (hv.val = "1")
but this is an assignment (evaluated as true, in your code): check for equality is ==
(equality by value) or ===
(equality by value and type)
you have used = operator which is used for assignment for comparison == operator is used try this In your if statement try this
if(hv.val=="1")