11/09/2012, 17:11
|
| | Fecha de Ingreso: septiembre-2012 Ubicación: Madrid
Mensajes: 89
Antigüedad: 12 años, 4 meses Puntos: 1 | |
Respuesta: [ERROR] onClick + .submit Sigue sin irme... :S.
Código:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript">
function addContent(divName, content)
{
document.getElementById(divName).innerHTML += content;
}
function loggear()
{
var frm = document.forms['loggingForm'];
var OK = true; // al ser true te envía el submit
var errorDescription='Falta dato';
// Borra los mensajes de error
document.getElementById('usernameError').innerHTML = '';
document.getElementById('passwordError').innerHTML = '';
if ( frm.elements['username'].value == "" )
{
document.getElementById('usernameError').innerHTML = errorDescription;
OK = false;
}
if ( frm.elements['password'].value == "" )
{
document.getElementById('passwordError').innerHTML = errorDescription;
OK = false;
}
if ( OK ) // Si vamos a enviar el formulario para que se procese...
{
// Borramos el botón "entrar"
boton = document.getElementById('buttonLogginID');
padre = boton.parentNode;
padre.removeChild(boton);
// Añadirmos texto al div
addContent('midiv', '<p>Iniciando sesión...</p>');
document.forms['loggingForm'].submit(); // Hacemos submit al formulario y nos comunicamos con PHP
}
return OK; // Enviamos el formulario para que sea procesado
}
</script>
</head>
<body>
<div id="midiv">
<form name="loggingForm" method="post" onsubmit="return loggear();">
<input name="username" type="text" placeholder="Usuario" /><p id="usernameError"></p>
<input name="password" type="password" placeholder="Contraseña" /><p id="passwordError"></p>
<input name="entrar" id="buttonLogginID" type="submit" value="Entrar" />
</form>
</div>
</body>
</html>
<?php
if ( isset($_POST['entrar']) ) // Si pulsamos el botón "buttonLoggin"
{
?><script type="text/javascript">alert('user correcto');</script><?php
}
?>
|