0
I have more than one Button inside the form. And I need one of them to perform a javascript function while the other performs Submit. But it turns out the two of them are performing Ubmit, and I need the button to be in the form. The "Confirm" button performs Ubmit and the other should perform the eye function(), but it tbm ta working as Ubmit, even if it is of type button. Then I would have to prevent the event Ubmit and perform the eye function(), but I can’t do it. I thank you already.
function olho() {
if (document.getElementById('senha').type == 'password') {
document.getElementById('senha').type = 'text';
var img = document.getElementById('img-olho');
img.src = 'img/olho-fechado.svg';
} else {
document.getElementById('senha').type = 'password';
var img = document.getElementById('img-olho');
img.src = 'img/olho-aberto.svg';
}
}
<form id="form" method="POST" action="#">
<label id="label-user">Usuário:</label>
<input type="text" name="usuario" id="usuario" placeholder="Digite seu email..."><br>
<label id="label-senha">Senha:</label>
<input type="password" name="senha" id="senha" placeholder="Digite a senha...">
<button type="button" onclick="olho()" id="olho"><img id="img-olho" src="img/olho-aberto.svg"/></button>
<button type="submit" id="botao">Confirmar</button>
</form>