title: Multiple Drop-Down Menus Based on Selected Value of First Drop-Down
body: <p>I have been searching for similar questions but they are a little different to what I am looking for.</p>
  
  <p>Basically, this is what I am aiming to implement:</p>
  
  <p>Have a first drop-down list filled with values, e.g. :</p>
  
  <pre><code>&lt;form&gt;
  &lt;select id="tags" name="tags"&gt;
  &lt;option value="agent" selected="selected"&gt;agent&lt;/option&gt;
  &lt;option value="extension"&gt;extension&lt;/option&gt;
  &lt;option value="fileversion" &gt;fileversion&lt;/option&gt;
  &lt;option value="pages"&gt;pages&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Then, in a second drop-down list, show options dependant on what was selected, for example, if agent is selected, the operators would be <code>=</code> or <code>!=</code> since it is text. For fileversion there would be 4 operands, <code>=</code>, <code>!=</code>, <code>&gt;</code> and <code>&lt;</code>.</p>
  
  <p>Lastly, there would be a third drop-down with values also dependant on the initially selected option.</p>
  
  <p>For example, when agent is selected, the options would be <code>pdf</code>, <code>word</code>, <code>excel</code>, <code>ppt</code> etc. and others it would just be a <code>text box</code> to type in rather than exhaust all possible values.</p>
  
  <p>In the end this will be used to search a database but it is a big db and the searches are too slow so I'm thinking the values for the options will be stored in an array rather than pulled directly.</p>
  
  <p>As you can see, it's fairly tricky :/ any help at all is much appreciated.</p>
  
  <p>Thanks,
  Martin</p>
  
  <p>EDIT:</p>
  
  <p>Found  the answer for those who happen to be looking for the same answer:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;script type="text/javascript" src="js/jquery-1.4.2.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/dropdown.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form&gt;
  &lt;select id="tags" name="tags"&gt;
  &lt;option value="tags" selected="selected"&gt;tags&lt;/option&gt;
  &lt;option value="agent"&gt;agent&lt;/option&gt;
  &lt;option value="extension"&gt;extension&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;select name="operands"&gt;
  &lt;option&gt;operands&lt;/option&gt;
  &lt;/select&gt;
  &lt;/form&gt;
  &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>dropdown.js:</p>
  
  <pre><code>$(document).ready(function() {
  $tags = $("select[name='tags']");
  $operands = $("select[name='operands']");
  
  $tags.change(function() {
  
  if ($(this).val() == "agent") {
  $("select[name='operands'] option").remove();
  $("&lt;option&gt;=&lt;/option&gt;").appendTo($operands);
  $("&lt;option&gt;!=&lt;/option&gt;").appendTo($operands);
  }
  
  if ($(this).val() == "extension") 
  {
  $("select[name='operands'] option").remove();
  $("&lt;option&gt;.pdf&lt;/option&gt;").appendTo($operands);
  $("&lt;option&gt;.doc&lt;/option&gt;").appendTo($operands);
  }
  
  if ($(this).val() == "tags") 
  {
  $("select[name='operands'] option").remove();
  $("&lt;option&gt;operands&lt;/option&gt;").appendTo($operands);
  }
  
  });
  });
  </code></pre>