Foros del Web » Programando para Internet » Javascript »

Se muestra un elemento undefined que no existe.

Estas en el tema de Se muestra un elemento undefined que no existe. en el foro de Javascript en Foros del Web. Hola Estoy haciendo una pagina html + javascript. Dentro de un fieldset, empiezo a añadir una serie de elementos: input, button, ... Cuando llega la ...
  #1 (permalink)  
Antiguo 25/02/2014, 08:09
Avatar de laqmaslocaesta  
Fecha de Ingreso: octubre-2012
Mensajes: 26
Antigüedad: 11 años, 5 meses
Puntos: 1
Pregunta Se muestra un elemento undefined que no existe.

Hola

Estoy haciendo una pagina html + javascript.

Dentro de un fieldset, empiezo a añadir una serie de elementos: input, button, ...

Cuando llega la hora de mostrarlo, aparece tal y como queria, pero añade un elemento, es solo texo y pone UNDEFINED.

Este "elemento", aparece al final de documento.

En la posición en la que sale, no hay ningun documento, por lo que no se proque sale, ni como quitarlo.

Alguien me puede ayudar a quitarlo???
  #2 (permalink)  
Antiguo 25/02/2014, 08:25
Colaborador
 
Fecha de Ingreso: septiembre-2013
Ubicación: España
Mensajes: 3.648
Antigüedad: 10 años, 7 meses
Puntos: 578
Respuesta: Se muestra un elemento undefined que no existe.

Enseña el código.
  #3 (permalink)  
Antiguo 25/02/2014, 08:38
Avatar de 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>



  #4 (permalink)  
Antiguo 07/03/2014, 06:51
Avatar de 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.

Hola?? Nadie que pueda ayudarme??

he subido una imagen de el pantallado señalando en rojo el elemento undefined.

http://subefotos.com/ver/?4fa9643fd5c5616c57a72878b6b7c8d9o.jpg

Por favor, ayuda!!, me pasa en todas la paginas que creo!!!

Saluods
  #5 (permalink)  
Antiguo 11/03/2014, 07:46
Avatar de 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.

Ya he encontrado la solución, por si ha alguien le vuelve a pasar.

El problema esta en como llamaba a la funcioón javascript desde el html.

La forma correcta es la sigueinte.

Código HTML:
<form >
<fieldset id="fiel">
<script>crear()</script>
</fieldset>
</form>
</body>
</html> 

Etiquetas: elemento, html, input, muestra, undefined
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:03.