Note that there are some explanatory texts on larger screens.

plurals
  1. POToggling visibility of next table row with checkbox in jQuery
    primarykey
    data
    text
    <p>I have 15 form elements on my page in the following format:</p> <pre><code>&lt;tr&gt; &lt;td colspan="3" class="fieldset-table-field-3-span"&gt; @Html.EditorFor(model =&gt; model.ExistingProductId_MappingName_IsFreeText) &lt;/td&gt; &lt;/tr&gt; </code></pre> <p>When the checkbox is in the checked state, I would like the next row to be visible:</p> <pre><code>&lt;tr&gt; &lt;td colspan="3" class="fieldset-table-field-3-span"&gt; @Html.EditorFor(model =&gt; model.ExistingProductId_MappingName_FreeText) &lt;/td&gt; &lt;/tr&gt; </code></pre> <p>I could write some JS/jQuery to hide the rows and toggle them on click, but wondered if anybody had a solution for toggling the state of the "next control" so I could hook it up to each checkbox in my form thus only having to do this once in order to adhere to DRY.</p> <p>Here's the markup from the first couple of rows:</p> <pre><code> &lt;table class="fieldset-table" align="center" cellpadding="3"&gt; &lt;tr&gt; &lt;td class="fieldset-table-label"&gt; &lt;label for="ExistingProductId_MappingName"&gt;Existing ID&lt;/label&gt; &lt;/td&gt; &lt;td colspan="3" class="fieldset-table-field-3-span"&gt; &lt;select id="ExistingProductId_MappingName" name="ExistingProductId_MappingName"&gt;&lt;option value=""&gt;-- Not Mapped --&lt;/option&gt; &lt;option value="Id"&gt;Id&lt;/option&gt; &lt;option value="Name"&gt;Name&lt;/option&gt; &lt;option value="Cost Price"&gt;Cost Price&lt;/option&gt; &lt;option value="Unit Price"&gt;Unit Price&lt;/option&gt; &lt;/select&gt; &lt;span class="field-validation-valid" data-valmsg-for="ExistingProductId_MappingName" data-valmsg-replace="true"&gt;&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="fieldset-table-label"&gt; &amp;nbsp; &lt;/td&gt; &lt;td colspan="3" class="fieldset-table-field-3-span"&gt; &lt;input class="check-box" data-val="true" data-val-required="The Free text field is required." id="ExistingProductId_MappingName_IsFreeText" name="ExistingProductId_MappingName_IsFreeText" type="checkbox" value="true" /&gt;&lt;input name="ExistingProductId_MappingName_IsFreeText" type="hidden" value="false" /&gt; &lt;label for="ExistingProductId_MappingName_IsFreeText"&gt;Free text&lt;/label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="fieldset-table-label"&gt; &lt;label for="ExistingProductId_MappingName_FreeText"&gt;Text value&lt;/label&gt; &lt;/td&gt; &lt;td colspan="3" class="fieldset-table-field-3-span"&gt; &lt;input class="text-box single-line" id="ExistingProductId_MappingName_FreeText" name="ExistingProductId_MappingName_FreeText" type="text" value="" /&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre>
    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.
 

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