Django Dropdown Auto send

Hi guys. I have a dropdown form for all companies. Now I want to display all the people who work in this company when the user changes the value in the drop-down list of the company without clicking the submit button on the form. Does anyone have a good example for this?

Tks

+3
source share
2 answers

Alex's answer is a good way, but here's an alternative. Django and slugs are going well. And unobtrusive javascript with jquery is the hip at the moment.

POSTing URL-. , SEO, , POST, - "".

, Alex my, , javascript . , - (, ).

(, )

<!-- you'll need jquery to make this work -->
<script type="text/javascript">
     $(function() {
          // navigate to page on click event
          $('#nav_combo').bind('change', function() { goToPage(); } );
     });

     function goToPage() {
      var baseUrl = '/your/base/url/';
      window.location.href = baseUrl + $('nav_combo').val()
     }
</script>

...

<form>
     <select id="nav_combo">
          <option value="page-1-slug">Page 1</option>
          <option value="page-2-slug">Page 2</option>
     </select>
</form>

. , , django object_detail generic view.

+3

Ajax, , Django , - ...:

<form name=companiesForm action="whateverurl" method=POST>
  <p>
  <select name=companySelect size=1 onChange="companiesForm.submit();">
    <option value="" SELECTED>Choose A Company
    <option value="1">One Company
    <option value="2">Another Company
    <option value="3">A Third Company
  </select>
  </p>
</form>
+8

Source: https://habr.com/ru/post/1718134/


All Articles