Check values in a form (Javascript) -




i've 5 variables in form, simplicity named them a, b, c, d , e. in order submit form (a or (b or c)) , (d or e) must have value (i hope it's clear :p). i've tried with

if ((a == "" || (b == "" || c == "")) && (d == "" || e == "")) {     alert ("error!"); } else {     form.submit(); } 

but doesn't work in every case. example, if a, b , c have value, form submitted if neither d or e have values. thank help!

if have strings, reverse condition , check logical , and 1 or.

var = '', b = '', c = '', d = '', e = '';        if (a && b && c || d && e) {      console.log('form.submit();');  } else {      console.log('error!');  }

why works:

given

(a == "" || (b == "" || c == "")) && (d == "" || e == "") 

simplified a == "" equivalent !a

(a == "" || b == "" || c == "") && (d == "" || e == "")  (!a || !b || !c) && (!d || !e) 

de morgan's laws !(a && b) = !a || !b or !(a || b) = !a && !b

 (!a || !b || !c) && (!d || !e)   !(a &&  b &&  c) && !(d &&  e)  !((a &&  b &&  c) ||  (d &&  e)) 

operator precedence

!(a && b && c || d && e) 

now switch/negate <-> else

a && b && c || d && e 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -