Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Check out this working <a href="http://jsfiddle.net/maximua/3RP94/" rel="nofollow">Fiddle</a>.</p> <p>The way you currently have it, every time toggleDisplay or toggleDisplay1 is called - it sends same 'mydiv' and 'mydiv1' parameters. What it should do instead is it has to find options inside same row.</p> <pre><code>toggleDisplay = function() { var target = event.target || event.srcElement; $(target).closest("td").find("div").hide(); $(target).closest("td").find("div:eq("+$(target).index("input[name="+$(target).attr("name")+"]")+")").toggle(); }; </code></pre> <p>To add a new row you could clone the first row:</p> <pre><code>addRow = function(tableID) { var table = document.getElementById(tableID); var oClone = table.rows[0].cloneNode(true); $(oClone).find("input[type=radio]").each(function(){ $(this).attr("name", "radio"+table.rows.length); }); $(oClone).find("div").hide(); table.insertBefore(oClone); }; </code></pre> <p>Also your radio buttons have different names, thus they are not behaving properly:</p> <pre><code>&lt;TABLE id="dataTable" border="1"&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="text" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" /&gt;&lt;/td&gt; &lt;td&gt; &lt;input type="radio" name="radio0" onClick="toggleDisplay();"/&gt;Own &lt;input type="radio" name="radio0" onClick="toggleDisplay();"/&gt;Contractor &lt;div style="display:none;"&gt; &lt;input type="radio" name="Wage" value="Wage"/&gt;Wage Board &lt;input type="radio" name="Staff" value="Staff"/&gt;Staff &lt;/div&gt; &lt;div style="display:none;"&gt; Name Of Contractor:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;input type="text" name = "text" /&gt; &lt;input type="radio" name="No" /&gt;No of Workmen &lt;/div&gt; &lt;/td&gt; &lt;td&gt;&lt;input type="text" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/TABLE&gt; &lt;input type=button onclick="addRow('dataTable')" value="add row" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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