简体   繁体   中英

Append input of type file into form jquery

Below is the piece of code that i have written,

var form = $('<form/>', {action : 'myServlet', method : 'POST', name : 'myForm', id: 'myForm'}).appendTo('body');
form.append("<textarea name='description' id='description' value=''/>");
form.append("<textarea name='title' id='title' value=''/>");

$('#description').val($scope.rsp.observations);
$('#title').val($scope.rsp.title);
$('#myForm').submit();

Now I have to add an input of type file into this form and append, and also i have to save a file in this tag. How can this be done so that my output looks like

<form id="myForm" method="post" action="myservlet">
    <input type="file" name="attachment">
    <textarea name="description" id="description">
    <textarea name="title" id="title">
</form>

Here the input file type must contain a file stored in a variable.

You must need to select file manually to upload due to security reason, here you can create and append input field file. but can't send hard code value or path to server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM