Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, problem is cool. :) Here is the solution.</p> <p><strong>HTML Markup</strong></p> <pre><code>&lt;div class="formContainer"&gt; &lt;div class="row"&gt; &lt;div class="flt"&gt; &lt;select name="items" id="items"&gt; &lt;option value="1"&gt;1&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div class="flt"&gt;&lt;textarea name="description" id="description"&gt;&lt;/textarea&gt;&lt;/div&gt; &lt;div class="flt"&gt;&lt;input type="text" name="unitprice" id="unitprice" /&gt;&lt;/div&gt; &lt;div class="flt"&gt;&lt;input type="text" name="quantity" id="quantity" /&gt;&lt;/div&gt; &lt;div class="flt"&gt; &lt;select name="firsttax" id="firsttax"&gt; &lt;option value="1"&gt;1&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div class="flt"&gt; &lt;select name="secondtax" id="secondtax"&gt; &lt;option value="1"&gt;1&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;div class="flt"&gt;&lt;input type="text" name="linetotal" id="linetotal" readonly /&gt;&lt;/div&gt; &lt;div class="flt"&gt;&lt;input type="button" class="addRow" name="addRow" value="+" /&gt;&lt;/div&gt; &lt;div class="flt"&gt;&lt;input type="button" class="removeRow" name="removeRow" value="-" /&gt;&lt;/div&gt; &lt;div class="clr"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>CSS</strong> </p> <pre><code>.fieldRow { margin-bottom: 20px; overflow: hidden; } .fieldRow .field { float: left; margin: 0 10px 0 0; } .fieldRow select.field { padding: 1px; } .buttonHolder { border-top: solid 5px #ccc; padding: 10px; } #template .button.remove { display: none; } </code></pre> <p><strong>And JavaScript:</strong></p> <pre><code>$(function(){ var rowItem = $(".row"); $(".formContainer").on("click", ".addRow", function(){ var newItem = rowItem.clone(), rowIndex = $(".row").length; $(":input", newItem).each(function(c, obj){ $(obj).attr("id", $(obj).attr("name") + rowIndex); }); //$(this).parent().parent().after(newItem); // adds just after the current line $(".formContainer").append(newItem); // adds At the end of the container }) .on("click", ".removeRow", function(){ if($(".row").length &gt; 1){ $(this).parents(".row").remove(); } }); }); </code></pre> <p>You have two ways to add the row:</p> <ol> <li>If want to add just after the current row</li> <li>If want to add the row at the end of the form</li> </ol> <p>Both are there in the JS above, (one is commented as of now)</p> <p>Here is the working Demo: <a href="http://jsfiddle.net/ashishanexpert/8pJ4P/1/" rel="nofollow">http://jsfiddle.net/ashishanexpert/8pJ4P/1/</a></p> <p><em>If you like animations, you can check out this one:</em> <a href="http://jsfiddle.net/ashishanexpert/8pJ4P/4/" rel="nofollow">http://jsfiddle.net/ashishanexpert/8pJ4P/4/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload