Foros del Web » Programando para Internet » Jquery »

[SOLUCIONADO] Serialize.. con inputs dinamicos(Problema)

Estas en el tema de Serialize.. con inputs dinamicos(Problema) en el foro de Jquery en Foros del Web. Hola a todos... Pues tengo un formulario con 2 inputs(input text y un input file-multiple).. Lo que estoy haciendo es que cuando selecciono varios archivos ...
  #1 (permalink)  
Antiguo 26/05/2015, 09:28
Avatar de wunderwaffen077  
Fecha de Ingreso: marzo-2014
Mensajes: 45
Antigüedad: 10 años, 1 mes
Puntos: 3
Serialize.. con inputs dinamicos(Problema)

Hola a todos...

Pues tengo un formulario con 2 inputs(input text y un input file-multiple)..
Lo que estoy haciendo es que cuando selecciono varios archivos se me crean tantos inputs text como archivos he seleccionado..

El problema es que cuando uso la función SERIALIZE, no me coge los inputs dynamicos..
Código HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="JavaScript"> 
		var ihtml = '';
		$(function(){
			$("#cmd_Enviar").live("click",function(){
				var frm1 = $('#frm1').serialize();
			
				var val = $(".files").val();
				
				
				
				console.log(frm1);
				console.log(val);
				
			});
			
			
			$("#file_3").live("change",function() {
				var names = [];
				var x=0;
				for (var i = 0; i < $(this).get(0).files.length; ++i) {
					var name = $(this).get(0).files[i].name;
					names.push(name);					
					
					ihtml += '<input type="text" id="file"'+i+'" class="files" value="'+name+'"></input><br\>';					
					ihtml += '<input type="text" id="'+i+'"></input><br\>';
					
				}
				
				
				$(".result_files").html(ihtml);
				
			});
			
			
		
			
			
			
		});
		
      function copia(valor,e){
        u=valor.replace("C:\\fakepath\\","");
        
        //document.frm_.getElementById(e).value = u;     
        document.getElementById(e).value=u;
      }
    </script>

</head>
<body>
    <form id="frm1"  name="frm1" method="post" enctype="multipart/form-data">        
      
       
		 <div id="FileUpload">
            <input type="file" id="file_3" multiple="" name="file_3" />
            <div id="BrowserVisible"><input type="text" name="FileField3" id="FileField3"  /></div>
        </div>
		<div class="result_files">			
		</div>
		
        <input type="button" id="cmd_Enviar" name="submit" value="Subir Archivos" />
    </form>

</body>
</html> 
  #2 (permalink)  
Antiguo 26/05/2015, 09:43
Avatar de wunderwaffen077  
Fecha de Ingreso: marzo-2014
Mensajes: 45
Antigüedad: 10 años, 1 mes
Puntos: 3
Respuesta: Serialize.. con inputs dinamicos(Problema)

Bueno me respondo solo..

El problem esta en esta linea..
ihtml += '<input type="text" id="file"'+i+'" class="files" value="'+name+'"></input><br\>';

Falto asignarle un nombre como en abajo..
ihtml += '<input type="text" id="file"'+i+'" name="file"'+i+'" class="files" value="'+name+'"></input><br\>';



Eso es todo amigos...xD

Etiquetas: dinamico, input, serialize
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 20:37.