Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
class CronForm(forms.Form):
days = forms.ModelChoiceField(queryset=Day.objects.all().order_by('day'))
class Day(models.Model):
day = models.CharField(max_length=200, default='')
month = models.CharField(max_length=200, default='')
def __unicode__(self):
return self.day
And It is shown at the template this way:
<form method="post" onchange=change()>
{{ days }}
</form>
What I want is to submit this form when the user selects an option from the dropdown list. For example, the user could be redirected to a new url, and internally the program would capture the POST data. But everything I find is related to the <select>
tag, like calling a javascript function onchange of the select element. But as the select element is IN the ModelChoiceField form, I don't know how to do it.
Any help would be very appreciated!
–
Find the id
of the dropdown using firebug. It should be id_days
as you are using the name days
. Then bind jQuery change
event to it.
$(function(){
$('#id_days').change(function(){
$('#id_of_form').submit();
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.