1

to start off i am showing the user one file input field and they can click "add one" to add one input field, however when they have already chosen a file and afterwards click "add input field" the chosen files for all previous input fields disappear. Is there a way to correct this?

here's my javascript function:

  function _add_more() {
    var txt = "<br><input type=\"file\" name=\"item_file[]\">";
    document.getElementById("files").innerHTML += txt;
  }

here's my html form:

<div id="form">

<h4>BOWMAN - Add an album <a href="index.php"> back</a></h4>
<form method="post" action="procesblogpost.php" enctype="multipart/form-data">
  <label for="title">Give the album it's name</label><br/>
  <input type="text" id="title" name="title" /><br/><br/>

  <label for="info">some info about the album?</label><br/>
  <textarea id="info" name="info"></textarea><br/><br/>
  <div id="uploadpic">
      <label for="picturelink">now choose some pictures</label><br/>
      <div id="files">
          <input type="file" name="item_file[]">
      </div>
      <a href="javascript:_add_more();" title="Add more">+</a>
  </div>
  <br/><br/>
  <input type="submit" id="submit" name="submit" value="send it of to the www" />
</form>

</div>

1 Answer 1

2

You may try this

function _add_more() {
    var txt = document.createElement('input');
    txt.type="file";
    txt.name="item_file[]";
    document.getElementById("files").appendChild(txt);
}

DEMO.

Sign up to request clarification or add additional context in comments.

Comments

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.