How to retrieve values from an HTML form for a Javascript function

1

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

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

Thank you for your attention right away.

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>
    
asked by anonymous 10.11.2018 / 06:59

1 answer

0

To get the data of a <input> you can use id of it and get into JavaScript using the document.getElementById('senha_input').value function.

Answer with other options

    
10.11.2018 / 15:53