Ver Mensaje Individual
  #6 (permalink)  
Antiguo 09/06/2010, 17:11
Joseph
 
Fecha de Ingreso: febrero-2003
Mensajes: 233
Antigüedad: 21 años, 2 meses
Puntos: 4
Respuesta: Mejorar el código

Hola, no me funcionó... la verdad creo que modificando el original cambie algo mal, lo volví a adpatar sin modificar mucho y me funcionó, aca le dejo el código para quien lo necesite, me parece bueno.

Código javascript:
Ver original
  1. <script language=javascript>
  2.  
  3. function validarFormulario(){
  4.  
  5. var isNotOk;
  6.  
  7.  
  8. var usuario = window.document.formValidar.usuario.value;
  9. if (usuario==""){
  10.  
  11. document.getElementById("iusuario").style.display="inline";
  12.  
  13. isNotOk=true;
  14.  
  15. }
  16. else{
  17.  
  18. document.getElementById("iusuario").style.display="none";
  19.  
  20. }
  21.  
  22.  
  23. var clave = window.document.formValidar.clave.value;
  24. if (clave==""){
  25.  
  26. document.getElementById("iclave").style.display="inline";
  27.  
  28. isNotOk=true;
  29. }
  30. else{
  31.  
  32. document.getElementById("iclave").style.display="none";
  33. }
  34.  
  35.  
  36. var email = window.document.formValidar.email.value;
  37. if (email==""){
  38.  
  39. document.getElementById("iemail").style.display="inline";
  40.  
  41. isNotOk=true;
  42. }
  43. else{
  44.  
  45. document.getElementById("iemail").style.display="none";
  46. }
  47.  
  48.  
  49.  
  50. var pais = window.document.formValidar.pais.value;
  51. if (pais==""){
  52.  
  53. document.getElementById("ipais").style.display="inline";
  54.  
  55. isNotOk=true;
  56. }
  57. else{
  58.  
  59. document.getElementById("ipais").style.display="none";
  60. }
  61.  
  62. if (isNotOk){
  63. return 0;
  64.  
  65.  
  66. }
  67. else{
  68. window.document.formValidar.submit();
  69. }
  70.  
  71.  
  72.  
  73. }
  74. </script>
  75.  
  76. <form id="registro" name="formValidar" method="post" action="registro.asp">
  77.  
  78. <table align="center" cellpadding="5" cellspacing="0">
  79.  
  80. <tr>
  81. <td>Usuario:</td>
  82. <td>
  83. <input name="usuario" type=text id="usuario" maxlength=20></td>
  84. <td>
  85. <div id="iusuario" style="display:none; color:red">&nbsp;*</div></td>
  86. </tr>
  87. <tr>
  88. <td>Clave:</td>
  89. <td>
  90. <input name="clave" type=password id="clave" maxlength=20></td>
  91. <td>
  92.  
  93. <div id="iclave" style="display:none; color:red">&nbsp;*</div></td>
  94. </tr>
  95. <tr>
  96. <td>Email:</td>
  97. <td>
  98. <input name="email" type=text id="email" maxlength=50></td>
  99. <td>
  100.  
  101. <div id="iemail" style="display:none; color:red">&nbsp;*</div></td>
  102. </tr>
  103.  
  104. <tr>
  105.   <td>Pa&iacute;s:</td>
  106.   <input name="pais" type=text id="pais" maxlength=50></td> </td>
  107.   <td><div id="ipais" style="display:none; color:red">&nbsp;*</div></td>
  108. </tr>
  109. <tr>
  110.   <td>&nbsp;</td>
  111. </tr>
  112. <tr>
  113. </tr>
  114.  
  115. <tr><td>
  116. <input type=button name=btnTest id=btnTest value=Enviar onClick="validarFormulario()">
  117. </tr></td>
  118. </table>