Ver Mensaje Individual
  #3 (permalink)  
Antiguo 02/10/2011, 12:49
Avatar de cristian_cena
cristian_cena
Colaborador
 
Fecha de Ingreso: junio-2009
Mensajes: 2.244
Antigüedad: 14 años, 10 meses
Puntos: 269
Respuesta: tinyMCE y jquery, deja de funcionar para multiples textareas dinamicos

Comparto la solución para quien le sirva, dos archivos:

1 - multiples_textareas.html

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  3.     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  4.     <title></title>
  5.     <style type="text/css">
  6.     *{margin:0; padding:0;}
  7.     </style>
  8.     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
  9.     <script type="text/javascript" src="ruta/a/el/plugin/tiny_mce.js"></script>
  10.  
  11.     <script type="text/javascript" >
  12.  
  13.     var tinymceConfigs = [{
  14.             theme : "simple",
  15.             mode : "none",
  16.             },
  17.             {
  18.             theme : "simple",
  19.             mode : "none",
  20.             }];
  21.  
  22.     function addTiny(settingid,el_id) {
  23.         tinyMCE.settings = tinymceConfigs[settingid];
  24.         tinyMCE.execCommand('mceAddControl', true, el_id);
  25.     }
  26.    
  27.     $(function(){
  28.         addTiny(0,"ed0");
  29.         addTiny(1,"ed1");
  30.     });
  31.     ai = 2;
  32.     $("#agregar").live('click', function(){
  33.     identificador= "ed"+ai;
  34.         $("<textarea></textarea>", {id:identificador, name:'descripcion[]'}).appendTo("#formu");
  35.         addTiny(ai,identificador);
  36.     ai++;  
  37.     });
  38.    
  39.     </script>
  40.    
  41. </head>
  42.  
  43.     <form action="post.php" id="formulario" method="post">
  44.         <div id="formu">
  45.             <textarea name="descripcion[]" id="ed0"></textarea>
  46.             <textarea name="descripcion[]" id="ed1"></textarea>
  47.         </div>
  48.         <input type="submit" value="enviar" />
  49.         <input type="button" value="agregar" id="agregar" />
  50.     </form>
  51. </body>
  52.  
  53. </html>

2 - post.php

Código HTML:
Ver original
  1. <a href="multiples_textareas.html">volver</a>
  2. <pre>
  3. <?php
  4. $total = count($_POST["descripcion"]); //debuelve 3 y for empieza a contar de 0
  5. for ($i = 0; $i < $total; $i++) {
  6.    echo $_POST["descripcion"][$i];
  7. }
  8. //listo para insertar con felicidad en la base de datos.
  9. ?>
  10. </pre>


Este codigo es una adaptación de una solución que encontre acá.