How to recover the values of an HTML form for a Javascript function

Asked

Viewed 1,077 times

1

I have a page with a form made with Bootstrap and would need to recover the data submitted to a Javascript file external to HTML.

My main goal would be to retrieve the password field to make validations through the function ValidarSenha().

Thank you for your attention.

Follow the HTML code

<div class="col-sm-3">
                <form name="cadastro" class="form-set" action="/pagina-destino" onsubmit="return ValidaSenha()" method="post">
                    <div class="form-group">
                        <label for="nome">Nome</label>
                        <input type="text" class="form-control" id="nome" name="nome" placeholder="ex: João da Silva"/>
                    </div>
                    <div class="form-group">
                        <label for="email">Email</label>
                        <input type="email" class="form-control" id="email" name="email" placeholder="ex: [email protected]"/>
                    </div>
                    <div class="form-group">
                        <label for="senha">Senha</label>
                        <input type="password" class="form-control" id="senha" name="senha"/>
                    </div>
                    <div class="form-group">
                        <label for="csenha">Confirme sua senha</label>
                        <input type="password" class="form-control" id="csenha" name="csenha"/>
                    </div>  
                    <button type="submit" class="btn btn-warning">Enviar</button>
                </form>
            </div>

  • 1

    It is not very clear what exactly you are trying to do. Where do you need to use the data ? How do you want to use it ? What is the location of the file you want to use ? This file is JS or PHP ?

1 answer

1

To get the data from a <input> you can use the id and pick up Javascript using the function document.getElementById('senha_input').value.

Response with other options

Browser other questions tagged

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