View form when password is set

Asked

Viewed 80 times

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>

https://jsfiddle.net/4aq3gd5w/

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

I tried with :

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

but it doesn’t work.

4 answers

2

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

document.getElementbyId("cadastro").style.display = "block";
  • Thank you, ma’s not here yet.

2

Actually it’s not visibility and yes display try like this:

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

Alias your jsfiddle code is got a write error at the beginning: docuemnt.getElementbyName("cadastro").style.visibility:"visible"; this written docuement instead of Document.

  • I was testing your code on the link Voce sent and I noticed that the onClick method in the boot is not working. <br>I don’t know if it’s a jsfiddle error but do a test putting an Alert() at the beginning of the function to see if the onClick event is working.

  • Still working but not this function

2


I edited it in its code because it had many errors of writing.
To select an element in javascript, always use id(Document.getElementById) alias Voce was typing 'byId' with b minusculo and is higher (getElementById).
Follow 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="signup" to the hidden form.

  • Obg ! It’s OK like this.

1

  • Thank you I need it without button.

  • 2

    @Victor Gomes, could you add the code directly to the answer? and just quote the execution of the codepen? So there is no risk of people being invalidated because it is a link-only response! Thank you for understanding!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.