javascript django dropdownlist onchange 提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16076420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
django dropdownlist onchange submission
提问by toni
I am showing to the user a dropdown list from this form:
我正在向用户显示此表单中的下拉列表:
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!
我想要的是当用户从下拉列表中选择一个选项时提交此表单。例如,用户可以被重定向到一个新的 url,程序将在内部捕获 POST 数据。但我发现的一切都与<select>
标签有关,比如调用 select 元素的 javascript 函数 onchange。但是由于 select 元素在 ModelChoiceField 表单中,我不知道该怎么做。任何帮助将不胜感激!