0

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>
1
  • i try but when i set input and textarea but i need value as < input type='text' name='photo[]' value='file.jpg'/> Commented Jun 10, 2013 at 18:19

2 Answers 2

1

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');
        });
    },
Sign up to request clarification or add additional context in comments.

9 Comments

see i need it out of file.name insert into value of input as <input type="text" name="photo[]" value=file.name />
my form <form><input type="file" name="files[]" multiple="" id="fileupload"></form>
i don't replace form i need result of files uploaded insert into value of inputs
Yeah, I get that....whats the problem then??? is file.name even valid then? what happens if you console.log(file.name) does it actually show the filename?
out was <input type="text" name="photo[]" value="file.name"> not <input type="text" name="photo[]" value="image.jpg">
|
0

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/

2 Comments

out like <input type="text"> i try to make it as input type="text" name="photo[]" value="image.jpg">
The append is working for him, its the file.name he is having trouble with....I told him to console.log it to see if its empty or whatever since my code above is appending but not setting the value, it tells me file.name is either invalid or empty

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.