I’m making a long sign up form, and it’s fields need to be validated. Most of the inputs are just text, but there’s one checkbox for conditions and two radio buttons for gender.
So I’m trying to trigger validation if any of the inputs are empty, conditions aren’t checked or gender selected, and this isn’t working for me:
if(((Nimi&&Osoite&&Postinumero&&Postitoimipaikka&&Postinumero&&Puhelin&&Sahkoposti&&Kurssi&&Kurssilaiset&&Koiranimi&&Koiraika&&Koirarotu)=="") || ((Sukupuoli)=="Valitse")) || ((Ehdot):not(:checked))){
//Input validation
//Gender Validation
//Conditions?
}
There’s also a syntax error I think, but how would I get it working?
To be clear:
I want the validation only to trigger if any of the inputs is empty, checkbox not checked or radio selected.
Results in a boolean value that is
trueif all of those variables are non-“falsy” values andfalseif any are “falsy”. Then you are taking that boolean and comparing it to the empty string for equality. Aka, alwaysfalse.You need to explicitly compare all of them against the emtpy string. Also, you need to use the
||(or) operator. Because you want it to run if any are empty. Not just if all are.EDIT: I’ve changed the equality operators to
===which means the compare is strict and therefor non-type-converting. For example, here are some differences between “falsy” values using==and the strict comparisons with===: