jQuery: Conditional show an element based on drop down box selection
<p>I have two related drop-down lists, in which the contents in the second drop-down list depends on the selection made in the first one. For example, in the following HTML code, you will choose application method first. If you choose Aerial as the application method, then you will answer further question such as aerial size dist. Otherwise, you need to answer ground spray type. </p>

<p>So once the webpage is loaded, the two second level drop-down lists (aerial size dist., and ground spray type.) are hidden. They will appear only when related choice is made in the first one (application method).  </p>

<p>I am able to achieve this feature in jQuery (below jQuery code). But my approach is pretty stupid. My question is:</p>

<ol>
<li><p>Is there a way to select the whole row, without using counting its sequence (nth-child())? Can I choose the whole row, based on selecting an element ID ? For example, can I first select $('#id_A') and then expand my selection to the whole row?</p></li>
<li><p>Is there a better way (a loop?) to achieve this hide or show feature rather than comparing all the possible choices (($(this).val() == "X")  )? </p></li>
</ol>

<p>Thanks!</p>

<p>Here is the HTML code, and the form is generated by Django:</p>

<pre><code>&lt;div class="articles"&gt;
    &lt;form method="GET" action=_output.html&gt;
        &lt;table align="center"&gt;
&lt;tr&gt;&lt;th&gt;&lt;label for="id_application_method"&gt;Application method:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;select  name="application_method" id="id_application_method"&gt;
&lt;option value=""&gt;Pick first&lt;/option&gt;
&lt;option value="A"&gt;Aerial&lt;/option&gt;
&lt;option value="B"&gt;Ground&lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt;&lt;th&gt;&lt;label for="id_A"&gt;Aerial Size Dist:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;select name="aerial_size_dist" id="id_A"&gt;
&lt;option value="A1" selected="selected"&gt;A1&lt;/option&gt;
&lt;option value="A2"&gt;A2&lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt;&lt;th&gt;&lt;label for="id_B"&gt;Ground spray type:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;select name="ground_spray_type" id="id_B"&gt;
&lt;option value="B1" selected="selected"&gt;B1&lt;/option&gt;
&lt;option value="B2"&gt;B2&lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;                  
&lt;/form&gt;
&lt;/div&gt;
</code></pre>

<p>Here is the jQuery code:</p>

<pre><code>&lt;script type="text/javascript" src=" https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"&gt;&lt;/script&gt; 

&lt;script&gt;$(function() {
    $("tr:nth-child(2)").hide();
    $("tr:nth-child(3)").hide();

    $('#id_application_method').change(function() {
    ($(this).val() == "A") ? 
    $("tr:nth-child(2)").show() : $("tr:nth-child(2)").hide();

    ($(this).val() == "B") ? 
    $("tr:nth-child(3)").show() : $("tr:nth-child(3)").hide();
    });});&lt;/script&gt;
</code></pre>
