Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>ok so I revised allot of code here is the <a href="http://jsfiddle.net/mcgrailm/MEg83/" rel="nofollow">WORKING DEMO</a> by making the measures children of the outcome it will save you parsing in the php side of things.</p> <p>I took out the names in the template portion to prevent them from posting. </p> <p>I copy the measure form one that's already close by and clear the value since there is no need to renumber everything since it will already be named correctly.</p> <p>I would also strongly suggest you take out the br span and strong tags those things should be handled with css or label would be a good idea </p> <p>here is the html</p> <pre><code>&lt;form action="#" method="post"&gt; &lt;div class="outcomegroup" id="template"&gt; &lt;div class="col"&gt; &lt;strong&gt;Outcome #&lt;span class="onum"&gt;1&lt;/span&gt;&lt;/strong&gt; &lt;img class="plus addoutcome" src="http://i54.tinypic.com/2zqzzo7.jpg" /&gt; &lt;img class="minus removeoutcome" src="http://i53.tinypic.com/29apc8i.jpg" /&gt; &lt;br /&gt; &lt;textarea class="outcome"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;div class="col"&gt; &lt;div class="measure1"&gt; &lt;textarea&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;div class="measure"&gt; &lt;textarea&gt;&lt;/textarea&gt; &lt;img class="plus addmeasure" src="http://i54.tinypic.com/2zqzzo7.jpg"/&gt; &lt;img class="minus removemeasure" src="http://i53.tinypic.com/29apc8i.jpg"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="outcome-measure-fields"&gt;&lt;/div&gt; &lt;input type="submit" value="submit" /&gt; &lt;/form&gt; </code></pre> <p>and the jquery here:</p> <pre><code>function renumber() { $('#outcome-measure-fields .outcomegroup').each(function(index, value) { $(this).find('.outcome').attr('name', 'outcomes[' + index + '][outcome]'); $(this).find('.measure textarea').attr('name', 'outcomes[' + index + '][measure][]'); $(this).find('.measure1 textarea').attr('name', 'outcomes[' + index + '][measure][]'); $(this).find('.onum').text(index + 1); }); } $('.addmeasure').live('click', function() { $(this).closest('.measure').clone().insertAfter($(this).closest('.measure')).val('').find('.minus').show(); }); $('.addoutcome').live('click', function() { $('#template').clone().removeAttr('id').insertAfter($(this).closest('.outcomegroup')).find('.minus').show(); renumber(); }); $('.removeoutcome').live('click', function() { $(this).closest('.outcomegroup').remove(); renumber() }); $('.removemeasure').live('click', function() { $(this).closest('.measure').remove(); }); $('#template').clone().appendTo($('#outcome-measure-fields')).removeAttr('id'); renumber() </code></pre> <p>and of course your css</p> <pre><code>.outcomegroup { overflow: auto; } #template { display: none; } .col { float: left; margin: 5px; font-size: 20px; font-weight: bold; } .plus, .minus { width: 20px; margin: 2px; vertical-align: middle; position: relative; top: -3px; } .minus { display: none; } </code></pre> <p>let me know how it goes</p>
 

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