claudios claudios - 6 months ago 15
jQuery Question

Add dynamic input field in ajax

Is there a way to put a dynamic input inside ajax? I am using hayageek jquery file upload. I wanted to add an input as hidden inside the form upload for replacing a file. Any help would be much appreciated.

The div that handles upload:

<div id="replacefile">Upload</div>


I wanted to put:
<input type="text" name="replace">


$("#replacefile").uploadFile({
url : newurl,
fileName : "myfile",
returnType : "json",
dragDrop : true,
showFileCounter: false, // show numbered list of file
allowDuplicates: false,
multiple : true, //allow multiple file upload
showFileSize : false, // show file size
acceptFiles : "doc,pdf",
onSuccess : function(files,data,xhr,pd) {
// success
},
onError : function() {
// error
}
});

Answer
$("#replacefile").uploadFile({
    url            : newurl,
    fileName       : "myfile",
    returnType     : "json",
    dragDrop       : true,
    showFileCounter: false, // show numbered list of file
    allowDuplicates: false,
    multiple       : true, //allow multiple file upload
    showFileSize   : false, // show file size
    acceptFiles    : "doc,pdf",
    onSuccess      : function(files,data,xhr,pd) {
     // success 

        var input=$('<input type="text" name="replace">');
        $('#replacefile').find('form').append(input);
    },
    onError        : function() {
     // error
    }
  });
Comments