Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/05/2010, 13:27
Avatar de _cronos
_cronos
 
Fecha de Ingreso: abril-2010
Mensajes: 135
Antigüedad: 14 años
Puntos: 1
Validación formulario

Bueno pues como el título dice estoy intentando hacer la validación de un formulario. Pongo aquí el código que uso a ver si podeis ver dónde está el error.

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <title>Formulario</title>
  4. <style type="text/css">
  5. <!--
  6. .Estilo1 {
  7.     font-family: "Colonna MT";
  8.     color: #FFFFFF;
  9.     font-size: 18px;
  10. }
  11. .Estilo2 {font-size: 18px;}
  12. * {left: 2px;}
  13. body {
  14.     background-color: #000000;
  15. }
  16.  
  17. -->
  18. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /></head>
  19. <div style="background-image:url(http://www.tuswallpapersgratis.com/images/wallpapers/Fuego_Reflejado_1024x768-275502.jpeg);">
  20.  <div class="Estilo1"><h1>Datos</h1></div>
  21.  <div class="Estilo1" style="text-align:justify; text-align:center;">Si tu navegador es IE, es posible que esté bloqueando algunas partes de la página. Si es así, te saldrá una ventana de aviso de bloqueo de ventanas emergentes. Sólo tienes que hacer click en ella y en 'Permitir contenido bloqueado'.</div>
  22.   <form id='entrada' action="mailto:[email protected]" method="post" enctype="application/x-www-form-urlencoded" onsubmit="return envio();">
  23.   <input type='hidden' name="Formulario" value="Ikariam ext" />
  24.   <span class="Estilo1">Indica tu:
  25.   </span><br />
  26.   <div class="Estilo1"><ul>
  27.  <li><div class="Estilo1">Nombre:</div></li>
  28.    <input type='text' id='nombre' size="20" /><br /><br /><br />
  29.  <li><div class="Estilo1">Puntuación: </div></li>
  30.    <select id='puntos'>
  31.    <option value="0" selected="selected">0 </option>
  32.    <option value="1-5,000">1-5,000</option>
  33.    <option value="5,001-10,000">5,001-10,000</option>
  34.    <option value="10,001-20,000">10,001-20,000</option>
  35.    <option value="20,001-30,000">20,001-30,000</option>
  36.    <option value="30,001-50,000">30,001-50,000</option>
  37.    <option value="50,001-75,000">50,001-75,000</option>
  38.    <option value="75,001-100,000">75,001-100,000</option>
  39.    <option value="+100,000">+100,000</option>
  40.   </select>
  41.    <br /><br /><br />
  42.  <li><div class="Estilo1">Número de colonias:</div></li>
  43.   <select id='colonias'>
  44.    <option value="0" selected="selected">0</option>
  45.    <option value="1">1</option>
  46.    <option value="2">2</option>
  47.    <option value="3">3</option>
  48.    <option value="4">4</option>
  49.    <option value="5">5</option>
  50.    <option value="+5">+5</option>
  51.   </select>
  52.   <br /><br />
  53.   <li><div class="Estilo1">Coordenadas:</div></li>
  54.     <fieldset style='width:20%;'>
  55.    <br />&nbsp;<span class="Estilo1">X:</span>
  56.    <input type='text' id='coordenadasx' size='15'/><br /><br /><br />
  57.   <span class="Estilo1">&nbsp;Y:</span>
  58.   <input type='text' id='coordenadasy' size='15' /><br />
  59.  </fieldset><br />
  60.   </ul></div>
  61.   <input type="submit" value="Enviar datos" />   <input type='reset' value="Restablecer datos" />
  62.   </form>
  63.   <span class="Estilo1">&nbsp;Deja aquí tu comentario (1000 carácteres máx.): </span>
  64.   <form action="mailto:[email protected]" method="post" enctype="application/x-www-form-urlencoded" id="comid">
  65.    &nbsp;
  66.    <textarea id="coment" cols='55' rows='17' onkeypress="caract()"></textarea>
  67.    <pre></pre>&nbsp;<input type='text' id='numc' value="1000" size="7" ReadOnly />
  68.    <br /><br />
  69.    &nbsp;<input type='submit' value="Enviar comentario" />  <input type='reset' value="Borrar" />
  70.   </form>
  71. </div>
  72. </body>
  73. </html>

Código Javascript:
Ver original
  1. <script language="javascript" type="text/javascript">
  2.    var d = document;
  3.    function envio(){    
  4.     if (document.getElementById('nombre').value.length==0){
  5.       alert("Escribe tu nombre, por favor");
  6.       document.getElementById('nombre').focus();
  7.       return false;
  8.     }else{
  9.     return true;
  10.     }  
  11.  
  12.     if (document.getElementById('coordenadasx').value.length==0){
  13.       alert("Escribe tus coordenadas, por favor");
  14.       document.getElementById('coordenadasx').focus();
  15.       return false;
  16.     }else{
  17.     return true;
  18.     }
  19.    
  20.     if (isNaN(document.getElementById('coordenadasx').value)){
  21.       alert("Escribe un número válido, por favor");
  22.       document.getElementById('coordenadasx').focus();
  23.       return false;
  24.     }else{
  25.     return true;
  26.     }
  27.    
  28.     if (document.getElementById('coordenadasy').value.length==0){
  29.       alert("Escribe tus coordenadas, por favor");
  30.       document.getElementById('coordenadasy').focus();
  31.       return false;
  32.     }else{
  33.     return true;
  34.     }
  35.    
  36.     if (isNaN(document.getElementById('coordenadasy').value)){
  37.       alert("Escribe un número válido, por favor");
  38.       document.getElementById('coordenadasy').focus();
  39.       return false;
  40.     }else{
  41.     return true;
  42.     }
  43.  
  44.     if (document.getElementById('puntos').selectedIndex==0){
  45.       alert("Indica tus puntos, por favor");
  46.       document.getElementById('puntos').focus();
  47.       return false;
  48.     }else{
  49.     return true;
  50.     }
  51.  
  52.     if (document.getElementById('colonias').selectedIndex==0){
  53.       alert("Indica el número de colonias que posees, por favor");      
  54.       document.getElementById('colonias').focus();
  55.       return false;
  56.     }else{
  57.     return true;
  58.     }
  59.     alert("Muchas gracias, tus datos serán enviados");
  60.   }
  61.  function caract(){
  62.   var caracter = d.getElementById('coment').value.length;
  63.   var valor = d.getElementById('numc');
  64.   valor.value = 1000 - caracter;
  65.   if(caracter>=1000){
  66.    alert('Ya has alcanzado los 1000 carácteres, por favor envía este comentario y luego otro nuevo. Gracias.');
  67.    document.getElementById('coment').value = document.getElementById('coment').substring(0,1000)
  68.   }
  69.  }
  70. </script>

Muchas gracias desde ya,
Saludos (:
__________________
'Dadme un punto de apoyo y moveré el mundo' - Arquímedes
Alianza DIOSES [-GOD-] Ikariam - Mundo Ny (s13)