Ver Mensaje Individual
  #3 (permalink)  
Antiguo 03/06/2012, 13:27
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Como capturar VALUE del TEXTAREA del FCKEDITOR

Cita:
Iniciado por maycolalvarez Ver Mensaje
Los textarea NO manejan su contenido con value, use innerHTML, lo que para jQuery es .html(), consulte un manual de formularios en HTML
Permitime discrepar @maycolAlvarez

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>titulo</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  7. <script type="text/javascript">
  8. //<![CDATA[
  9. /* script */
  10. function valor_tarea(){
  11. var elemento = document.forms[0].elements["texto"];
  12. var t = elemento.value;
  13. alert('valor con name: \n' + t);
  14. var valor = document.getElementById('texto');
  15. alert('valor con id: \n' + valor.value)
  16. // innerHTML
  17. alert('valor con innerHTML: \n' + valor.innerHTML)
  18. }
  19. //]]>
  20. </head>
  21. <form action="#" onsubmit="return valor_tarea();" method="post">
  22. <textarea name="texto" id="texto" rows="3" cols="25">
  23. párrafo en textarea
  24. otra linea
  25. <br />
  26. <input type="button" value="con jQuery" id="eltxt" /><br />
  27. <input type="submit" value="con Jscript" />
  28. </form>
  29.  
  30.  
  31. <script type="text/javascript">
  32. //<![CDATA[
  33. $(document).ready(function(){
  34. $('#eltxt').click(function(){
  35. var tx = $("#texto").val();
  36. alert('Con jquery + val(): ' + tx);
  37. var tx2 = $("#texto").text();
  38. alert('Con jquery + text(): ' + tx2);
  39. var tx3 = $("#texto").html();
  40. alert('Con jquery + html(): ' + tx3);
  41. });
  42. });
  43. //]]>
  44. </body>
  45. </html>

Como se ve, el val(), o value es recogido siempre.
Ahora en particular, para este caso, no habría que usar html() ó text() de jQuery ó innerHTML de javascript, porque en Firefox/Chrome, por ejemplo, siempre obtendríamos el contenido por defecto (no así en IE). Si el usuario modifica contenido solo se afecta el val() ó value, que en todos los navegadores se comportará igual
con respecto al problema de @mesoriginal, sin ver toda la script, asumo que esta definiendo
var tx = $("#texto").val();
fuera del evento click

Saludos

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.

Última edición por emprear; 03/06/2012 a las 13:58