Multiple <select> elements with one <input> element?

36 views
Skip to first unread message

Gchorn

unread,
Sep 6, 2012, 10:53:59 PM9/6/12
to django...@googlegroups.com
Hi All,

I'm trying to create a form on a web page where the user can select choices from multiple drop-down lists (<select> HTML elements) and then submit them all at once with a single submit button.  Is this possible?

I don't want to use a single <select> element with the "multiple" attribute because the list of options may be quite long, and I find it quite clunky for the user to have to hold ctrl/command/shift down while clicking on multiple options in such a long list (it's easy to accidentally release one of the keys and have to start over, etc.).

I've also used this for something similar in the past, but I want to limit the number of selected options to only four at once (which is another reason I also don't want to use <select> with "multiple").

So does anyone know how I could make something like the following work, both in terms of HTML and views.py (and without JS)?

<form>
  <select>
    <option>one</option>
    <option>two</option>
    <option>buckle</option>
    <option>shoe</option>
  </select>
  <select>
    <option>three</option>
    <option>four</option>
    <option>shut</option>
    <option>door</option>
  </select>
  <input type="submit" value="Submit"/>
</form>

I'm guessing that in views.py it would be something like request.GET.getlist('q'), but as far as I know you're supposed to give each <select> element a different name, right?

thanks,
Guillaume

Jeff Regan

unread,
Sep 7, 2012, 1:43:25 AM9/7/12
to django...@googlegroups.com
You might look into using jQuery to get the results and then post the results (also using jQuery) to some url.  

This approach doesn't really fit the Django pattern, but it should work.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/dcFM0INbXCAJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply all
Reply to author
Forward
0 new messages