title: Use JQUERY/JSON to auto fill select dropdown boxes
body: <p>OK I spent spent a lot of time looking over examples but can't find one which helps me enough for my situation. I have a JSON file, simplified for this example:</p>
  
  <pre><code>{
   "Company":[
      {
          "Position": "Manager",
          "Name": {
                              "11": "joe",
                              "12": "bill",
                              "166": "John"
                              }
      },
  {
  
          "Position": "Tech",
          "Name": {
                              "11": "Bob",
                              "12": "Cindy",
                              "166": "Karl"
                              }
      },
  {
  
          "Position": "Sales",
          "Name": {
                              "11": "Sam",
                              "12": "Ron",
                              "166": "Sara"
                              }
      }
  ]}
  </code></pre>
  
  <p>I am trying to create 2 select boxes. When the user selects the first box of positions, it will auto-fill the second with the attributes (names). So here is what I have so far:</p>
  
  <pre><code>&lt;select id="job"&gt;&lt;/select&gt;
  &lt;select id="name"&gt;&lt;/select&gt;
  </code></pre>
  
  <p>and the code:</p>
  
  <pre><code>$select = $('#job');
  $select2 = $('#name');
  
  $.ajax({
      url: 'factors.json',
      dataType: 'JSON',
      success: function(data) {
  
          $select.html('');
          $.each(data.Company, function(key, val) {
              $select.append('&lt;option id="' + key + '"&gt;' + val.Position + '&lt;/option&gt;');
  
  
  
              $("#job").change(function() {
                  $.each(val.Name, function(key2, val2) {
                      $select2.append('&lt;option id="' + key2 + '"&gt;' + val2 + '&lt;/option&gt;');
                  })
              })
          })
      },
  });​
  </code></pre>
  
  <p>This code will autofill the second box with ALL the names in every position. I jsut can't seem to figure out how to fill it with the names of each unique object. Thanks for any help!</p>