11👍
✅
The {{ form.start_date }} expands to:
<input id="id_start_date" type="something">
You can always right-click and inspect the element in most of the modern browsers.
So use:
var a = document.getElementsById("id_start_date").val;
I suggest you use the jQuery version:
var a = $("#id_start_date").val();
2👍
try this also if you want to directly get values
var start_date="{{ form.data.start_date }}"
👤Aks
1👍
The form is rendered automatically as valid html. You can access form fields by their id using the prefix id_field_name
. So start_date
field has id id_start_date
:
var a = document.getElementsById("id_start_date").val;
You should read documentation on form rendering here
- [Django]-User permissions for Django module
- [Django]-Django– Deactivate User account instead of deleting it
- [Django]-How to make a Django admin readonly textarea field
- [Django]-Passing context from child to parent template in Django
- [Django]-Django admin ignores has_delete_permission
Source:stackexchange.com