View form when the password is set

0

I have this code:

<html>
 <head>
    <script>
      function validarSenha(){
        senha1 = document.f1.senha1.value
        senha2 = document.f1.senha2.value

        if (senha1 == senha2) {
        alert("PASS OK");
                document.getElementbyId("cadastro").style.visibility:"visible";
            }

      else
        alert("PASS KO")
        }
    </script>
</head>

 <body>

<form action="" name="f1">
    Password : <input type="password" name="senha1" size="20">
    <br>
    Confirm Password: <input type="password" name="senha2" size="20">
<br>
<input type="button" value="Validar" onClick="validarSenha()">
</form>

<form action="#" method="post" name="cadastro" style="display:none">

 </br><hr></br>

    <fieldset class="grupo">
           <div class="campo">
               <label for="nome">Name</label>
               <input type="text" id="nome" name="nome" style="width: 20em" value="" />
           </div>
           <div class="campo">
               <label for="cro">CRO</label>
               <input type="text" id="cro" name="cro" style="width: 5em" value="" />
           </div>
    </fieldset>
</form>

 </body>
</html>

link

I need the FORM registration to appear when the password has been set.

I've tried with:

document.getElementbyId("cadastro").style.visibility:"visible";

but it does not work.

    
asked by anonymous 18.03.2016 / 15:14

4 answers

2

I gave an edit in your code because it had many errors of writing. To select an element in javascript, always prefer to use the id (document.getElementById) alias you were writing the 'byId' with the smallest and is the maximum (getElementById). Here is the code working:

Javascript function:

function validarSenha(){

    senha1 = document.getElementById("senha1").value;
    senha2 = document.getElementById("senha2").value;

    if (senha1 == senha2) {
        alert("PASS OK");
        document.getElementById('cadastro').style.display = 'block';
    }

    else {
        alert("PASS KO");
    }
}

And add the id="password1" and id="password2" to the inputs, and id="register" to the hidden form.

    
18.03.2016 / 19:42
2

use the same property you used in form to make it invisible ... ie display :

document.getElementbyId("cadastro").style.display = "block";
    
18.03.2016 / 15:21
2

Actually it is not visibility and yes display it tries like this:

if (senha1 == senha2) { alert("PASS OK"); document.getElementbyId("cadastro").style.display="block"; }

Alias your code in jsfiddle is have a writing error at the beginning: docuemnt.getElementbyName("cadastro").style.visibility:"visible";  This is written docuement instead of document.

    
18.03.2016 / 15:24
1

What you can do is a kind of hide and show, those famous "hide / show" buttons, but tailored to your needs.

link

    
18.03.2016 / 15:31