Jump to content

Login form close unexpectedly when I press a button element


raynerdurand

Recommended Posts

Hi, I need your help please, I have created a button element in the HTML file, to which assigned the "click" event with a jquery code in a java script file. The problem is that.. when the page is loaded for first time and I open the login form when I press the login button my form close suddenly and it shows "?#" at the end of the URL, I don't know why happens this and I appreciate your help.

thanks a lot.

Link to comment
Share on other sites

here I attached a part of the js file and I annexed part of the html file:

<form id="formLogin">
<h3 class="h3Form">INGRESE SUS DATOS</h3> 
<label id="label_correo" class="labelForm">Correo: </label><br> 
<input id="correo" type="text" title="Ingrese el correo introducido en el proceso de registro" 
class="inputs"/>
<img id="iconCorrectCorreo" class="iconCorrectLog" src="css/img/iconCorrecto.png">
<img id="iconErrorCorreo" class="iconErrorLog" src="css/img/iconError.png"><br> 
<label id="label_pass" class="labelForm">Password: </label><br> 
<input id="passLog" type="password" title="Ingrese su contraseña" class="inputs"/>
<img id="iconCorrectPassLog" class="iconCorrectLog" src="css/img/iconCorrecto.png">
<img id="iconErrorPassLog" class="iconErrorLog" src="css/img/iconError.png"><br>
<label id="label_typeUser" class="labelForm">Tipo de Usuario: </label><br> 
<select id="typeUser">
<option value="cliente">Cliente</option>
<option value="admin">Administrador</option>
</select>
<img id="iconCorrectTypeUser" class="iconCorrectLog" src="css/img/iconCorrecto.png">
<img id="iconErrorTypeUser" class="iconErrorLog" src="css/img/iconError.png"><br> 
<button id="buttonLogin" class="botones">LOGIN</button>
<a id="recuperaPass" href="#">Recuperar Password</a>
<div class="msjFormsLog"><h5 id="msjLogError"></h5></div>
</form>  

jsCode.txt

Link to comment
Share on other sites

You have to prevent the form from submitting. Instead of assigning the event to the submit button assign it to the form. Then call preventDefault() on the event object to stop the form from submitting.

$('#formLogin').submit(iniciarSesion);


function iniciarSesion(e) {
  "use strict";
  e.preventDefault();
  // El resto del código sigue a partir de aquí
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...