Ver Mensaje Individual
  #3 (permalink)  
Antiguo 25/02/2014, 08:38
Avatar de laqmaslocaesta
laqmaslocaesta
 
Fecha de Ingreso: octubre-2012
Mensajes: 26
Antigüedad: 11 años, 5 meses
Puntos: 1
Respuesta: Se muestra un elemento undefined que no existe.

Código:
Código HTML:
<!DOCCTYPE html>
<html>
<head>
<title>Pagina Acceso</title>
<script language="javascript">

function crear(){



	fi=document.getElementById('fiel');
//Primero limipamos el contenido anterior para evitar la multiplicacion del formulario.
fi.innerHTML="";

fi.style.border="none";

var div=document.createElement("div");
div.style.margin="auto";
//div.style.border="ridge";
div.style.textAlign="center";




	ele=document.createElement('br');
	div.appendChild(ele);

	ele=document.createElement('br');
	div.appendChild(ele);

div.appendChild(document.createTextNode('Username '));

	ele=document.createElement('input');
	ele.type='text';
	ele.id='nombre';
	div.appendChild(ele);

	ele=document.createElement('br');
	div.appendChild(ele);

div.appendChild(document.createTextNode('Password '));

	ele=document.createElement('input');
	ele.type='text';
	ele.id='pass';
	div.appendChild(ele);

	ele=document.createElement('br');
	div.appendChild(ele);

ele=document.createElement('input');
	ele.type='button';
	ele.id='Submit';
	ele.value='Entrar';
	ele.onclick=function(){consulta()};
	div.appendChild(ele);



fi.appendChild(div);

var sol=document.createElement("div");
sol.id='sol';
sol.style.textAlign="center";

fi.appendChild(sol);


}

function consulta()
{

var nombre=document.getElementById("nombre").value;
var pass=document.getElementById("pass").value;

if ((nombre=="") || (pass==""))
  {

	document.getElementById("sol").innerHTML="No se han introducido datos en el formulario";

  return;
  }

var xmlhttp;    
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  { 
  if (xmlhttp.readyState==4)
    {
	//Texto a ejecutar cuando llega la respuesta
	var personas=JSON.parse(xmlhttp.responseText);
	//Miraremos que tipo de mensaje nos han enviado
	//tipo 0 = El usuario no esta registrado
	//tipo 1 = El usuario es correcto y es el administrador
	//tipo 2 = El usuario es correcto y es un profesor
	//tipo 3 = El ususrio es correcto y es un alumno.

	if(personas.tipo==0){
	document.getElementById("txtHint").innerHTML= personas.mensaje;
	}else{//si nos hemos logueado correctamente nos iremos a la pagina correspondiente
	
	
	}
    }
  }

xmlhttp.open("GET","http://192.168.1.137:8080/pfc/",true);
xmlhttp.send();
}




</script>
</head>
<body>

<h2 align=center>Sign In</h2>
</br>


<form >
<fieldset id="fiel">
<script>document.write(crear()); </script>
</fieldset>
</form>
</body>
</html>