Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay options in a drop-down based on what is selected in another drop-down
    text
    copied!<p>I want to display options in a drop down menu based on what is already selected in another drop down menu. I have 16 options in the first drop-down, so I want to show different options in the second drop down for each selection in the first. I would like to do this using javascript or jquery. </p> <p>Here is the first drop down in my html file: </p> <pre><code> &lt;div&gt; &lt;label for="failureReason"&gt;Failure Reason:&lt;/label&gt; &lt;select id="failureReason" data-theme="a" data-icon="arrow-d" data-iconpos="right"&gt; &lt;option value="1"&gt;Damage&lt;/option&gt; &lt;option value="9"&gt;Calibration Failure&lt;/option&gt; &lt;option value="5"&gt;Component Failure&lt;/option&gt; &lt;option value="93"&gt;Customer Request&lt;/option&gt; &lt;option value="5"&gt;Error on Potted SUT&lt;/option&gt; &lt;option value="41"&gt;Installation Error&lt;/option&gt; &lt;option value="6"&gt;Interference&lt;/option&gt; &lt;option value="46"&gt;Network Issue&lt;/option&gt; &lt;option value="3"&gt;No Fault Found&lt;/option&gt; &lt;option value="8"&gt;No Power/Fuse Blown&lt;/option&gt; &lt;option value="23"&gt;Non-AMCS Issue&lt;/option&gt; &lt;option value="49"&gt;OBC HW Issue&lt;/option&gt; &lt;option value="30"&gt;OBC SW Issue&lt;/option&gt; &lt;option value="2"&gt;Training Issue&lt;/option&gt; &lt;option value="68"&gt;Truck Not Available&lt;/option&gt; &lt;option value="51"&gt;Routine Maintenance&lt;/option&gt; &lt;/select&gt; &lt;!-- Put in options for failure reason --&gt; &lt;/div&gt; </code></pre> <p>And I want to display different options inside this drop-down depending on what has been selected for "Failure Reason": </p> <pre><code>&lt;div&gt; &lt;label for="solutionId"&gt;Solution Id:&lt;/label&gt; &lt;select id="solutionId" data-theme="a" data-icon="arrow-d" data-iconpos="right"&gt; &lt;option value="1"&gt;Repaired&lt;/option&gt; &lt;option value="2"&gt;Restarted&lt;/option&gt; &lt;option value="3"&gt;Reinstalled Software&lt;/option&gt; &lt;option value="4"&gt;Replaced Loadcell&lt;/option&gt; &lt;option value="5"&gt;Replaced SUT&lt;/option&gt; &lt;/select&gt; &lt;!-- Put in options for Solution Id --&gt; &lt;/div&gt; </code></pre> <p>I've seen other examples, but nothing like what i'm trying to achieve. I need to be able to get the "value" of whatever option is shown and chosen for use in other parts of my javascript file.</p> <p>EDIT: </p> <p>I realise my question is a bit confusing. I'll try to be more clear. If "damage" is selected for failure reason, I want to show:</p> <pre><code>&lt;div&gt; &lt;label for="solutionId"&gt;Solution Id:&lt;/label&gt; &lt;select id="solutionId" data-theme="a" data-icon="arrow-d" data-iconpos="right"&gt; &lt;option value="1"&gt;Repaired&lt;/option&gt; &lt;option value="3"&gt;Reinstalled Software&lt;/option&gt; &lt;option value="4"&gt;Replaced Loadcell&lt;/option&gt; &lt;/select&gt; &lt;!-- Put in options for Solution Id --&gt; &lt;/div&gt; </code></pre> <p>But if "calibration failure" is chosen, I want to show:</p> <pre><code>&lt;div&gt; &lt;label for="solutionId"&gt;Solution Id:&lt;/label&gt; &lt;select id="solutionId" data-theme="a" data-icon="arrow-d" data-iconpos="right"&gt; &lt;option value="1"&gt;Repaired&lt;/option&gt; &lt;option value="2"&gt;Restarted&lt;/option&gt; &lt;option value="5"&gt;Replaced SUT&lt;/option&gt; &lt;/select&gt; &lt;!-- Put in options for Solution Id --&gt; &lt;/div&gt; </code></pre>
 

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