[Django]-How to get django form value in javascript without saving it into model

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

Leave a comment