Jump to content
raynerdurand

Login form close unexpectedly when I press a button element

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.

Share this post


Link to post
Share on other sites

What do your HTML and Javascript code look like?

Share this post


Link to post
Share on other sites

Are you canceling the default form submit? If not the page will reload when the form submits.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Where is iniciarSesion() in the code and where is id="linkLogin" in the HTML?

Share this post


Link to post
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í

Share this post


Link to post
Share on other sites
Hi.. after of some days and your help I think that I found the problem... this is related with the "mouseup" of the "Click" event.. then I have changed it, to "mousedown" event and solved problem.


thanks a lot for your help.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...