title: javascript function to select option and submit a django form
body: <p>I'm building an app in django and I've got a filter form that is a dropdown and you can switch between "new" and "popular" (aka filter by date or number of votes).  I decided  that I want this to be formatted as buttons (kind of like how it is on yik yak) where it is easier to toggle between the two.</p>
  
  <p>I am using django widget tweaks to display my forms so my generated HTML looks like:</p>
  
  <pre><code>&lt;form action="/board/Intuna/" method="post" class="ng-pristine ng-valid"&gt; 
      &lt;input type="hidden" name="csrfmiddlewaretoken" value="io55AwNMPKNzAkv69qWkcRzqNV7mwo1w"&gt;
      &lt;div class="form-group"&gt;
          &lt;label class="col-sm-1 control-label" for="id_filterType"&gt;Filter By&lt;/label&gt;
           &lt;div class="col-sm-11"&gt;
               &lt;select class="form-control" id="id_filterType" name="filterType" onchange="this.form.submit();"&gt;
                   &lt;option value="0" selected="selected"&gt;Most Recent&lt;/option&gt;
                   &lt;option value="1"&gt;Popularity&lt;/option&gt;
               &lt;/select&gt;
           &lt;/div&gt;
       &lt;/div&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>UPDATE: I tried writing this javascript function to select the choice in my form</p>
  
  <pre><code>function filter(valueToSelect) {
      var item = document.getElementById('id_filterType');
      console.log(item);
      if (item) {
          item.value = valueToSelect;
      }
  }
  </code></pre>
  
  <p>And lastly in my HTML template I have two buttons</p>
  
  <pre><code>&lt;button class="btn btn-primary" onclick="filter('0');"&gt;New&lt;/button&gt;
  &lt;button class="btn btn-primary" onclick="filter('1');"&gt;Hot&lt;/button&gt;
  </code></pre>
  
  <p>When I click the buttons, the selected option in my form changes but it doesn't submit, which does not make sense to me since it is supposed to automatically submit when the option is changed.  Any ideas?</p>