Search code examples
phpjqueryappendto

appendTo jquery add value to input


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>

Solution

  • 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');
            });
        },