javascript - add tr immediately after the button




You can use jQueryAfter(); and a click event, and make sure the input name is an array[]

     $('.uploads').last('tr').after('<tr align=center ><td colspan="4"><input type="file" name="oc[]"/></td></tr>');




jQuery can do this for you using.append() -

An untested example...

Here is the HTML,

<table id="table">
    <td><input type="file" name="file[]" /></td>
<button id="button">Add another</button>

and the javascript,

  var string = '<tr><td><input type="file" name="file[]" /></td></tr>';



You will need some JavaScript(JQuery) to accomplish your task.

Live Preview:

Place the following in a script tag before your closing body tag or load it from an external file after you load JQuery. If you are unsure how to load JavaScript through an external file you can download the example from this link and explore the index.html file.

Example Download

//store the addme id
var addMe = "#addme";

//store the tr markup
var tr = '<tr align=center ><td colspan="4"><input type="file" name="oc" id="oc"/></td><td><input type="button" value="add more" id="addme" /></td></tr>';

//add the on click event

  //select the table
  var table = $("#table"); 

  //append the tr


People are also looking for solutions to the problem: php - How to pass the search results specific component session into another page


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.