Answer the question
In order to leave comments, you need to log in
How to hide form field when radio buttons selection changes (in django)?
How can I make the comment field (label + field) only appear when CHOICE1 is selected? How to catch it from javascipt?
There is a form:
class CreateForm(forms.Form):
ORDER_CHOICES =(
("CHOICE1", "CHOICE1"),
("CHOICE2", "CHOICE2")
)
data = forms.DateField(label="Дата оказания услуги:", widget=forms.DateInput(attrs={'type': 'date'}), required=True)
time = forms.TimeField(label="Время оказания услуги:", widget=forms.TimeInput(attrs={'type': 'time'}), required=True)
status = forms.BooleanField(label="Заказ выполнен",initial=False, required=False)
order_type = forms.ChoiceField(label="Тип услуги:", choices = ORDER_CHOICES, widget=forms.RadioSelect(attrs={'onchange': 'showOrHide("id_order_type_0", "?what?")'}), required=True)
name = forms.CharField(label="ФИО заказчика:", max_length=60, required=False)
comment = forms.CharField(label="Комментарий:", widget=forms.Textarea, required=False)
<form method="POST" action="create/">
{% csrf_token %}
<table>
{{create_order.as_table}}
</table>
<input type="submit" value="Сохранить" >
<input type="submit" value="Отмена" name="cancel">
</form>
<script type="text/javascript">
function showOrHide(choice, disp) {
choice= document.getElementById(choice);
disp= document.getElementByWhat?(disp);
if (choice.checked) disp.style.display = "block";
else disp.style.display = "none";
}
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question