Ver Mensaje Individual
  #14 (permalink)  
Antiguo 11/11/2014, 06:47
caarool21
 
Fecha de Ingreso: noviembre-2014
Mensajes: 8
Antigüedad: 9 años, 6 meses
Puntos: 0
Respuesta: Al pasar HTML mediante .innerHTML no se queda el texto

Este es el JS

document.getElementById('formulario').onsubmit = function()
{


var DNI='';
var NOMBRE='';
var APELLIDOS='';

if (document.getElementById("dni").value == '')
{
DNI = ("El campo DNI no puede ser vacio");

}
if (document.getElementById("nombre").value == '')
{
NOMBRE = ("El campo nombre no puede ser vacio");

}
if (document.getElementById("apellidos").value == '')
{
APELLIDOS = ("El campo apellidos no puede ser vacio");

}



alert(DNI+'\n'+APELLIDOS+'\n'+NOMBRE);

var capa = document.getElementById('div_capa');
capa.innerHTML = DNI+ '<br>' +APELLIDOS+ '<br>'+NOMBRE;
capa.style.border = '1px solid red';


if(document.getElementById("dni").value != '' && document.getElementById("nombre").value != '' &&
document.getElementById("apellidos").value != '' ) {
return true;
}
else{
return false;
}
}


Y el html es este

<div id="div_capa">
</div>


<div id="div_form">

<form id="formulario">


<div id="div_datos_personales">

<fieldset>

<legend>Datos personales</legend>


<div id="div_dni">
<label id="label_dni" for="dni">D.N.I.:</label>
<input id="dni" name="dni" type="text" maxlength="8"/>-
<input id="letra" name="letra" type="text" maxlength="1"/>
</div>

<div id="div_nombre">
<label id="label_nombre" for="nombre">Nombre:</label>
<input id="nombre" name="nombre" type="text"/>
</div>

<div id="div_apellidos">
<label id="label_apellidos" for="apellidos">Apellidos:</label>
<input id="apellidos" name="apellidos" type="text"/>
</div>

</fieldset>

</div>

<div id="div_submit">
<input id="submit" type="submit" value="Enviar">
</div>

</form>

</div>


No he puesto ningún evento, ni onClick, ni submit, porque no sé qué poner. Antes lo tenía puesto en onClick con el nombre de la función, pero al eliminar la función no sé qué poner.