mercredi 2 septembre 2020

switch HTML form using javascript is annoying

this on my html file

<button>Login</button>
    <p class = "formmsg">need a new account? click <a href="#" onClick="return formChange(); return false" >here</a> to register </p>
      </form>

this is in my js file

function formChange(){
        
        document.getElementById("login-form").style.display = ((document.getElementById("login-form").style.display != 'none')? 'none' : 'flex');
        
        document.getElementById("register-form").style.display = ((document.getElementById("register-form").style.display != 'none')? 'none' : 'flex');
        
    }

i really new to this stuff (i'am using dreamweaver) and this is quite annoying because i've tried the normal if else statement which is won't work once i click another button and i have to double click it so it switching the register to login form, and now i'm working on this ternary operator and it is much worse because it only execute 1 statement only (i mean the form is completely disappear otherwise it shows both of them) please help me guys




Aucun commentaire:

Enregistrer un commentaire