Reputation: 93
how to add this value to input name value to print values as input to help me with forms
$('<textarea/>').text(file.name).appendTo('#files');
< input type='text' name='photo[]' value=''/>
i need to get our as < input type='text' name='photo[]' value='file.jpg'/>
can any one help me with it that
full code
<script>
/*jslint unparam: true */
/*global window, $ */
$(function () {
'use strict';
// Change this to the location of your server-side upload handler:
var url = (window.location.hostname === 'server/php/' ||
window.location.hostname === 'server/php/') ?
'//jquery-file-upload.appspot.com/' : 'server/php/';
$('#fileupload').fileupload({
url: url,
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<textarea/>').text(file.name).appendTo('#files');
});
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .bar').css(
'width',
progress + '%'
);
}
});
});
</script>
Upvotes: 0
Views: 1594
Reputation: 11749
Somehow I doubt you wanna append a textarea, so replace that with the real element you want to append ()...and append it to the formm... So if your html looks like this..
<form id="files" action="" method="">
<textarea></textarea>
</form>
Then the code will be...
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<input type="text" name="photo[]" />').val(file.name).appendTo('#files');
});
},
Or try this...
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<input type="text" name="photo[]" value='+file.name+'/>').appendTo('#files');
});
},
Upvotes: 1
Reputation: 8672
use .val() instead of .text()
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<input type="text"/>').val(file.name).appendTo('#files');
});
},
EDIT: Proof of concept as jsFiddle: http://jsfiddle.net/b26tx/
Upvotes: 0