javascript - If a or b = null or no value then... Filling in last field overrides function? -


i have code:

if(document.getelementbyid('usertype_2').checked) {      if(a==null || a=="", b==null || b=="",          c==null || c=="", d==null || d=="",         k==null || k=="", e==null || e=="",          g==null || g=="", h==null || h=="",          j==null || j=="", k==null || k=="") {         document.forms["619new"]["next1"].disabled = true;         document.forms["619new"]["next1"].style.background='#fdfdfd';         document.forms["619new"]["next1"].style.color = 'lightgray';         document.forms["619new"]["next1"].style.border = 'none';         document.forms["619new"]["next1"].style.cursor = 'not-allowed';     }     else {         document.forms["619new"]["next1"].disabled = false;         document.forms["619new"]["next1"].style.background='#195dad';         document.forms["619new"]["next1"].style.color = 'lightgray';         document.forms["619new"]["next1"].style.border = 'none';         document.forms["619new"]["next1"].style.cursor = 'pointer';     } } 

it meant disable button unless fields entered. once entered button becomes clickable.

this works. however... if decide fill last field in first overrides other fields , unlocks button when others empty.

i have tried find fix have become stuck. can help?

the reason seeing behavior because using comas inside if statement. surprise javascript accepts them fine result of operation value of last operand. check answer here why javascript accept commas in if statements?

update:

change coma || try changing way add , remove disabled attribute button. , last try use ! negate statements because checking not take account case undefined.

if(document.getelementbyid('usertype_2').checked) {     if(!a || !b || !c ||        !d || !e || !f || !g ||         !h || !i || !j || !k ) {         document.forms["619new"].next1.disabled = "disabled";         document.forms["619new"].next1.style.background='#fdfdfd';         document.forms["619new"].next1.style.color = 'lightgray';         document.forms["619new"].next1.style.border = 'none';         document.forms["619new"].next1.style.cursor = 'not-allowed';     }     else {         delete document.forms["619new"].next1.disabled;         document.forms["619new"].next1.style.background='#195dad';         document.forms["619new"].next1.style.color = 'lightgray';         document.forms["619new"].next1.style.border = 'none';         document.forms["619new"].next1.style.cursor = 'pointer';     } } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -