Foros del Web » Programando para Internet » Javascript »

No logro recibir los datos enviados de un textarea

Estas en el tema de No logro recibir los datos enviados de un textarea en el foro de Javascript en Foros del Web. Hola muchacho(a)s tengo un problema, tengo un script que me copia los datos de un textarea a otro, todo funciona muy bien pero ahora que ...
  #1 (permalink)  
Antiguo 01/02/2011, 08:36
Avatar de kaninox  
Fecha de Ingreso: septiembre-2005
Ubicación: In my House
Mensajes: 3.597
Antigüedad: 18 años, 6 meses
Puntos: 49
No logro recibir los datos enviados de un textarea

Hola muchacho(a)s tengo un problema, tengo un script que me copia los datos de un textarea a otro, todo funciona muy bien pero ahora que quiero enviar cualquiera de los dos textareas via POST me doy cuenta que no envio nada....

como puedo enviar los datos.

mi script es :
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. function Move_Select(objSourceElement, objTargetElement)
  3. {
  4.    var aryTempSourceOptions = new Array();
  5.    var aryTempTargetOptions = new Array();
  6.    var x = 0;
  7.    //looping through source element to find selected options
  8.    for (var i = 0; i < objSourceElement.length; i++) {
  9.         if (objSourceElement.options[i].selected) {
  10.             //need to move this option to target element
  11.             var intTargetLen = objTargetElement.length++;
  12.             objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
  13.             objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
  14.         }else {
  15.             //storing options that stay to recreate select element
  16.             var objTempValues = new Object();
  17.              objTempValues.text = objSourceElement.options[i].text;
  18.              objTempValues.value = objSourceElement.options[i].value;
  19.              aryTempSourceOptions[x] = objTempValues;
  20.              x++;
  21.         }
  22.    }
  23.  
  24.    //sorting and refilling target list
  25.    for (var i = 0; i < objTargetElement.length; i++) {
  26.     var objTempValues = new Object();
  27.     objTempValues.text = objTargetElement.options[i].text;
  28.     objTempValues.value = objTargetElement.options[i].value;
  29.     aryTempTargetOptions[i] = objTempValues;
  30.    }
  31.  
  32.    aryTempTargetOptions.sort(sortByText);
  33.  
  34.    for (var i = 0; i < objTargetElement.length; i++) {
  35.     objTargetElement.options[i].text = aryTempTargetOptions[i].text;
  36.     objTargetElement.options[i].value = aryTempTargetOptions[i].value;
  37.     objTargetElement.options[i].selected = false;
  38.    }
  39.    
  40.    //resetting length of source
  41.    objSourceElement.length = aryTempSourceOptions.length;
  42.    //looping through temp array to recreate source select element
  43.    for (var i = 0; i < aryTempSourceOptions.length; i++) {
  44.     objSourceElement.options[i].text = aryTempSourceOptions[i].text;
  45.     objSourceElement.options[i].value = aryTempSourceOptions[i].value;
  46.     objSourceElement.options[i].selected = false;
  47.    }
  48.      }
  49.  
  50.      function sortByText(a, b)
  51.      {
  52.    if (a.text < b.text) {return -1}
  53.    if (a.text > b.text) {return 1}
  54.    return 0;
  55.      }
  56.  
  57.      function selectAll(objTargetElement)
  58.      {
  59.    for (var i = 0; i < objTargetElement.length; i++) {
  60.     objTargetElement.options[i].selected = true;
  61.    }
  62.    return false;
  63.   }
  64.  
  65.   function seleccionar(obj) {
  66.         a = new Array();
  67.         elem=document.getElementById(obj).options;
  68.         for(i=0;i<elem.length;i++)
  69.         {
  70.         //elem[i].selected=true;   
  71.         //alert(elem[i].value);
  72.        
  73.         a[i] = elem[i].value
  74.        
  75.         }
  76.         //elem[0].value = implode(a);
  77.         //elem[0].selected= true;
  78.         //a = new Array(0,1,2,3,4,5,6,7,8,9);
  79.         return implode(a);
  80.   }
  81.   function implode(array){
  82.   var imploded=array[0];
  83.   for (i=1; i<array.length; i++)imploded += '+' + array[i];
  84.   return imploded
  85. }
  86. function llenardatos_select(LI,origen,destino)
  87. {
  88.         var datos = LI.split("+");
  89.         for (i=0; i < datos.length; i++)
  90.         {
  91.                 //alert (lineainv[i]);
  92.                 document.getElementById(origen).value = datos[i];
  93.                 Move_Select(document.getElementById(origen),document.getElementById(destino))
  94.         }
  95. }function Move_Select(objSourceElement, objTargetElement)
  96. {
  97.    var aryTempSourceOptions = new Array();
  98.    var aryTempTargetOptions = new Array();
  99.    var x = 0;
  100.    //looping through source element to find selected options
  101.    for (var i = 0; i < objSourceElement.length; i++) {
  102.         if (objSourceElement.options[i].selected) {
  103.             //need to move this option to target element
  104.             var intTargetLen = objTargetElement.length++;
  105.             objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
  106.             objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
  107.         }else {
  108.             //storing options that stay to recreate select element
  109.             var objTempValues = new Object();
  110.              objTempValues.text = objSourceElement.options[i].text;
  111.              objTempValues.value = objSourceElement.options[i].value;
  112.              aryTempSourceOptions[x] = objTempValues;
  113.              x++;
  114.         }
  115.    }
  116.  
  117.    //sorting and refilling target list
  118.    for (var i = 0; i < objTargetElement.length; i++) {
  119.     var objTempValues = new Object();
  120.     objTempValues.text = objTargetElement.options[i].text;
  121.     objTempValues.value = objTargetElement.options[i].value;
  122.     aryTempTargetOptions[i] = objTempValues;
  123.    }
  124.  
  125.    aryTempTargetOptions.sort(sortByText);
  126.  
  127.    for (var i = 0; i < objTargetElement.length; i++) {
  128.     objTargetElement.options[i].text = aryTempTargetOptions[i].text;
  129.     objTargetElement.options[i].value = aryTempTargetOptions[i].value;
  130.     objTargetElement.options[i].selected = false;
  131.    }
  132.    
  133.    //resetting length of source
  134.    objSourceElement.length = aryTempSourceOptions.length;
  135.    //looping through temp array to recreate source select element
  136.    for (var i = 0; i < aryTempSourceOptions.length; i++) {
  137.     objSourceElement.options[i].text = aryTempSourceOptions[i].text;
  138.     objSourceElement.options[i].value = aryTempSourceOptions[i].value;
  139.     objSourceElement.options[i].selected = false;
  140.    }
  141.      }
  142.  
  143.      function sortByText(a, b)
  144.      {
  145.    if (a.text < b.text) {return -1}
  146.    if (a.text > b.text) {return 1}
  147.    return 0;
  148.      }
  149.  
  150.      function selectAll(objTargetElement)
  151.      {
  152.    for (var i = 0; i < objTargetElement.length; i++) {
  153.     objTargetElement.options[i].selected = true;
  154.    }
  155.    return false;
  156.   }
  157.  
  158.   function seleccionar(obj) {
  159.         a = new Array();
  160.         elem=document.getElementById(obj).options;
  161.         for(i=0;i<elem.length;i++)
  162.         {
  163.         //elem[i].selected=true;   
  164.         //alert(elem[i].value);
  165.        
  166.         a[i] = elem[i].value
  167.        
  168.         }
  169.         //elem[0].value = implode(a);
  170.         //elem[0].selected= true;
  171.         //a = new Array(0,1,2,3,4,5,6,7,8,9);
  172.         return implode(a);
  173.   }
  174.  
  175.   function implode(array){
  176.   var imploded=array[0];
  177.   for (i=1; i<array.length; i++)imploded += '+' + array[i];
  178.   return imploded
  179. }
  180.  
  181. function llenardatos_select(LI,origen,destino)
  182. {
  183.         var datos = LI.split("+");
  184.         for (i=0; i < datos.length; i++)
  185.         {
  186.                 //alert (lineainv[i]);
  187.                 document.getElementById(origen).value = datos[i];
  188.                 Move_Select(document.getElementById(origen),document.getElementById(destino))
  189.         }
  190. }
  191. </script>

Mi Codigo es :
Código PHP:
Ver original
  1. <form method="post" action="pp.php" style="margin:0;padding:0;">
  2. <select name="disciplina" size="5" multiple="multiple" id="disciplina" style="width:352px;" onChange="javascript:Move_Select(this.form.disciplina, this.form.listadisciplina)" >
  3. <option value="1">disciplina 1</option>
  4. <option value="2">disciplina 2</option>
  5. <option value="3">disciplina 3</option>
  6. </select><br />
  7. <select id="listadisciplina" name="listadisciplina" size="5" multiple="multiple"  style="width:365px;" onChange="Move_Select(this.form.listadisciplina, this.form.disciplina)">
  8. <option value="4">disciplina 4</option>
  9. <option value="5">disciplina 5</option>
  10. <option value="6">disciplina 6</option>
  11. </select>
  12. <br />
  13. <input type="text" name="algo" value="2">
  14. <br />
  15. <input type="submit" name="enviar" value="Enviar">
  16. </form>
  17. <?php
  18. echo "$_POST[listadisciplina] - $_POST[algo]";
  19. ?>

el algo lo puse para probar que no este cometiendo yo un error pero nada :/
alguna idea?
__________________
Gokuh Salvo al mundo. PUNTO!!!!
  #2 (permalink)  
Antiguo 01/02/2011, 08:40
Avatar de jotaincubus  
Fecha de Ingreso: mayo-2005
Ubicación: Medellin - Colombia
Mensajes: 1.797
Antigüedad: 18 años, 10 meses
Puntos: 394
Respuesta: No logro recibir los datos enviados de un textarea

La pagina que tiene el codigo php se llama pp.php ? o es otra pagina la que recibe los datos ?
__________________
Por que existe gente que no agradece después de que se le ha brindado tiempo y ayuda ???
  #3 (permalink)  
Antiguo 01/02/2011, 09:00
Avatar de kaninox  
Fecha de Ingreso: septiembre-2005
Ubicación: In my House
Mensajes: 3.597
Antigüedad: 18 años, 6 meses
Puntos: 49
Respuesta: No logro recibir los datos enviados de un textarea

es la misma y no hay caso que pueda recibir los datos, alguna idea.
__________________
Gokuh Salvo al mundo. PUNTO!!!!
  #4 (permalink)  
Antiguo 01/02/2011, 09:04
Avatar de jotaincubus  
Fecha de Ingreso: mayo-2005
Ubicación: Medellin - Colombia
Mensajes: 1.797
Antigüedad: 18 años, 10 meses
Puntos: 394
Respuesta: No logro recibir los datos enviados de un textarea

<?php
if (isset($_POST['enviar'])){
echo $_POST['listadisciplina']." - ".$_POST['algo'];
}
?>
__________________
Por que existe gente que no agradece después de que se le ha brindado tiempo y ayuda ???

Última edición por jotaincubus; 01/02/2011 a las 09:13 Razón: Se me olvidaron unas comillas
  #5 (permalink)  
Antiguo 01/02/2011, 09:23
Avatar de kaninox  
Fecha de Ingreso: septiembre-2005
Ubicación: In my House
Mensajes: 3.597
Antigüedad: 18 años, 6 meses
Puntos: 49
Respuesta: No logro recibir los datos enviados de un textarea

jotaincubus lo probaste?
digo solo le agregaste el el boton la lista sigo sin recibirla, hasta donde he leido por hay hay que tratarla como arreglo pero por mas que le agrego disciplina[] por ejemplo tampoco me la toma he probado con un for y foreach y tampoco, alguno tiene alguna idea de que pueda estar pasando?

Saludos
__________________
Gokuh Salvo al mundo. PUNTO!!!!
  #6 (permalink)  
Antiguo 01/02/2011, 10:22
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 9 meses
Puntos: 2135
Tema movido desde PHP a Javascript
  #7 (permalink)  
Antiguo 01/02/2011, 11:29
Avatar de SirDuque  
Fecha de Ingreso: febrero-2009
Ubicación: Paso del Rey, Buenos Aires, Argentina
Mensajes: 975
Antigüedad: 15 años, 1 mes
Puntos: 89
Respuesta: No logro recibir los datos enviados de un textarea

Pregunta, probaste poner metodo GET, para ver si sale, a mi me pasa muy seguido y siempre resulta que me equivoco en el nombre de la variable etc. xD con metodo GET te sacas las dudas si sale del form o no xD.
__________________
Mono programando!
twitter.com/eguimariano
  #8 (permalink)  
Antiguo 01/02/2011, 12:24
Avatar de kaninox  
Fecha de Ingreso: septiembre-2005
Ubicación: In my House
Mensajes: 3.597
Antigüedad: 18 años, 6 meses
Puntos: 49
Respuesta: No logro recibir los datos enviados de un textarea

El tema es que si probaron el codigo me parece que no, este lo que hace es enviar info entre los dos textareas, si pincho en un textarea la info de ese pasa al otro y viceversa en tonces necesito enviar lo que hay completo en cada un de los textareas sin seleccionar la info por asi decirlo, y claramente no se envia nada.

Alguna idea al respecto
__________________
Gokuh Salvo al mundo. PUNTO!!!!
  #9 (permalink)  
Antiguo 01/02/2011, 12:42
Avatar de SirDuque  
Fecha de Ingreso: febrero-2009
Ubicación: Paso del Rey, Buenos Aires, Argentina
Mensajes: 975
Antigüedad: 15 años, 1 mes
Puntos: 89
Respuesta: No logro recibir los datos enviados de un textarea

Te cuento cual es el problema, estas usando una lista de select, y resulta que cuando le haces un clic lo sube o lo baja, pero no SELECCIONA NINGUNO!!!!! ;) fijate agrega selected alguna opcion, y envialo y vas a ver que funciona todo OK...

Que tendrias que hacer, todo lo que este abajo este SELECCIONADO. (osea todo lo que baje este en azul, que lo baje con "selected".
__________________
Mono programando!
twitter.com/eguimariano
  #10 (permalink)  
Antiguo 01/02/2011, 12:50
Avatar de kaninox  
Fecha de Ingreso: septiembre-2005
Ubicación: In my House
Mensajes: 3.597
Antigüedad: 18 años, 6 meses
Puntos: 49
Respuesta: No logro recibir los datos enviados de un textarea

Hola Sirduque pues esa es mi duda como recibo los parametros completos si no he seleccionado nada, de hecho si llego a seleccionar algo se pasa al select multiple de al lado, eso funciona como quiero el tema es como puedo enviar la info del select sin seleccionar los datos., el array completo.

Saludos
__________________
Gokuh Salvo al mundo. PUNTO!!!!
  #11 (permalink)  
Antiguo 01/02/2011, 13:14
Avatar de SirDuque  
Fecha de Ingreso: febrero-2009
Ubicación: Paso del Rey, Buenos Aires, Argentina
Mensajes: 975
Antigüedad: 15 años, 1 mes
Puntos: 89
Respuesta: No logro recibir los datos enviados de un textarea

La verdad que dudo puedas enviarlo usando ese metodo...
yo lo descartaria y buscaria otra opcion, ademas tenes otro problema...
cuando lo envia en metodo POST o GET, el PHP solo toma el ultimo ya que se esta pisando el nombre de la variable :/
__________________
Mono programando!
twitter.com/eguimariano
  #12 (permalink)  
Antiguo 01/02/2011, 13:33
Avatar de kaninox  
Fecha de Ingreso: septiembre-2005
Ubicación: In my House
Mensajes: 3.597
Antigüedad: 18 años, 6 meses
Puntos: 49
Respuesta: No logro recibir los datos enviados de un textarea

La verdad que yo se que se puede de hecho el código lo saque de un sistemita por hay el tema es que como no entiendo mucho el JS no se como envía los datos pero el sistema los recibe sin tener que estar seleccionando una opción.
Como se va a pisar el nombre de la variable? si estos datos se trabajan en arreglos? eso no lo entendi.

Por otra parte recién me vine a dar cuenta que puse textarea en el titulo y debería haber sido select multiple jajajaja ando de lokos...
__________________
Gokuh Salvo al mundo. PUNTO!!!!
  #13 (permalink)  
Antiguo 01/02/2011, 13:43
Avatar de kaninox  
Fecha de Ingreso: septiembre-2005
Ubicación: In my House
Mensajes: 3.597
Antigüedad: 18 años, 6 meses
Puntos: 49
Respuesta: No logro recibir los datos enviados de un textarea

Y bueno lo solucione, tomando el arreglo con javascript.

Les dejo la solucion
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. function tomaarreglo()
  3. {
  4.     seleccion = seleccionar('disciplina');
  5.     if (!seleccion) {}else{
  6.         document.formulario.disciplina.options[0].text    = seleccion;
  7.         document.formulario.disciplina.options[0].value   = seleccion;
  8.         document.formulario.disciplina.options[0].selected=true
  9.     }
  10.     window.document.formulario.submit();
  11. }
  12. </script>
__________________
Gokuh Salvo al mundo. PUNTO!!!!

Etiquetas: enviados, recibir, textarea
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 21:50.