Ver Mensaje Individual
  #4 (permalink)  
Antiguo 05/08/2010, 15:21
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Problema con bucles

Hola

Algunas modificaciones
Código Javascript:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html xmlns="http://www.w3.org/1999/xhtml"lang="es" xml:lang="es">
  3. <head>
  4. <script type="text/javascript">
  5. function alternar(t1, t2){
  6.  var txt = t1.value;
  7.  var aceptados = /[a-z\s]/;
  8.  var letras = new Array();
  9.  for (a = 0; a<txt.length; a++){
  10.   if(aceptados.test(txt.charAt(a))){
  11.    letras[letras.length] = a;
  12.   }
  13.  }
  14.  
  15. var cant = Math.round(Math.random()*letras.length);
  16.  
  17.  
  18.  
  19. var aleat = new Array();
  20. for (b = 0; b<cant-1; b++){
  21.  aleat[b] = Math.round(Math.random()*letras.length);
  22.  }
  23.  
  24.  
  25. nuevoArray = aleat.sort();
  26.  
  27. var mayuscula = '';
  28. var result = '';
  29. for(t = 0; t<txt.length; t++){
  30.  
  31.     for(z = 0; z < nuevoArray.length; z++) {
  32.      
  33.         if(t == nuevoArray[z]){
  34.             mayuscula = txt.charAt(letras[t])
  35.                 result += txt.charAt(letras[t]).toUpperCase();
  36.             break;
  37.             }
  38.  
  39.     }
  40.  
  41.     if(txt.charAt(letras[t]) != mayuscula) {
  42.          result += txt.charAt(letras[t]);
  43.         mayuscula = '';
  44.     }
  45.  
  46. }
  47.  
  48.  
  49.  t2.innerHTML = result;
  50. }
  51. </script>
  52.  
  53. </head>
  54. <body>
  55. <form>
  56. <input type="text" value="un texto cualquiera no importa el largo" id="texto" />
  57. <textarea id="resultado" /></textarea>
  58. <input type="button" value="Traer Formulario" onclick="alternar(document.getElementById('texto'), document.getElementById('resultado'))" />
  59. </form>
  60. </body>
  61. </html>
Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />