Ver Mensaje Individual
  #6 (permalink)  
Antiguo 05/02/2014, 15:03
Avatar de maracuyeaa
maracuyeaa
 
Fecha de Ingreso: febrero-2014
Mensajes: 14
Antigüedad: 10 años, 3 meses
Puntos: 0
Respuesta: Vista preliminar de un formulario en un textarea

Este es el código, pero no estoy dando doble clic!!

Código:
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>Formulario</title>

</head>

<body>

  <form method="post" onsubmit="return validateForm()" id="formulario">
    
    Nombre: <input type="text" name="Nombre" /><br/>
    
    Archivo: <input type="file" name="Archivo" /> <br/>
    
    Enviado desde: <select name="Enviado desde">
    
    <option value="Barcelona"> Barcelona</option>
    <option value="Sevilla"> Sevilla</option>
    <option value="Madrid"> Madrid</option>
    <option value="Valencia"> Valencia</option>
    
    </select>
    
     <input type="reset" onclick="borra()" value="Borrar"/> 
      
	<input type="submit" value="Enviar"/><br/>
      
         
	<textarea rows="20" cols="40" id="datos" readonly></textarea>

     
</form>
  
  
<script>

function validateForm()
{
var x=document.forms["formulario"]["nombre"].value;
if (x==null || x=="")
  {
  alert("El nombre es obligatorio.");
  return false;
  }


var x=document.forms["formulario"]["archivo"].value;
if (x==null || x=="")
  {
  alert("El archivo es obligatorio.");
  return false;}
  

var x=document.forms["formulario"]["opciones"].value;
if (x==null || x=="")
  {
  alert("El lugar es obligatorio.");
  return false;}
}

var formulario = document.getElementById("formulario"),
    textarea = document.getElementById("datos");

formulario.addEventListener("submit", function(e){
  e.preventDefault();
  
  for (i = 0, limite = formulario.elements.length; i < limite; i++)
    if (formulario.elements[i].getAttribute("type") != "submit")
      textarea.value += (formulario.elements[i].name) + ": " + formulario.elements[i].value + "\n";
}, 
false);

</script>


</body>
</html>

Última edición por maracuyeaa; 05/02/2014 a las 15:15