dimanche 6 juin 2021

Javascript ignoring if statements? [duplicate]

I've been tasked to have a php form object have a JS verification variable. Didn't say it had to actually work, but I think that's implicit in the requirement

So, obviously, for one reason or another, it cannot fetch the variable from the php object. I've tried a million different ways. And the most current one before I've completely given up on figuring it out, I've just created a hidden input. I tried doing .value, .textContent, and so on. But nothing's been working!

From what I can figure out, JS just ignores if statements that use variables without values. (And that fits, because no matter what I make the value or the check, it does not work. So, something's going wrong at the assignment portion. I just have no idea what it is.

var verify = document.getElementById('valid').value

if(verify != 0){
    //stuff it's only supposed to do if verify is not 0
    //but is still doing anyway
}

And here's the stupid hidden input

<input id="valid" type="hidden" value="0">

Aucun commentaire:

Enregistrer un commentaire