Change input value that used in different function. Django

So, I have an input field and I'm using that input field to save and edit a data. Basically, I use the same form to save and edit to database.

in my form.html I have this input.

  <label for="bar-title">Chart Title: </label>

  <input
    class="bg-white border shadow rounded w-96"
    type="text"
    id="bar-title"
    name="bar-title"
  />

in my save.html, save function.

function saveBarChart() {
    data = {};
    data.title = $("#bar-title").val();
     $.ajax({
            url: '{% url "url" %}',
            type: "POST",
            data: {
              id: id,
              csrfmiddlewaretoken: "{{ csrf_token }}",
              chart_data: JSON.stringify(data),
            },
          })
            .done(function (response) {
              console.log(response); //once send I will save the input value to database//
            })
            .fail(function (error) {
              if (error) notify(error);
            });
}

in my edit.html. I tried to set the value of input field by using the data from database. And if I tried to change the input field nothings change.

function setFormsValue(id) {
    $.ajax({
      type: "GET",
      url: `{% url 'get_data'  %}${id}`,
    }).done(function (response) {
             $(".update-barchart-wrapper input[name=bar-title]").val(response.name.title);
    });
  }

When I try to change the value by inputting some data into input field nothings changing. Once submitted, the value of input field is the same of the database even I edited it.

function editChartForm() {
var chartsRow = {};
chartsRow.title = $("#bar-title]").val();
console.log(chartsRow) 
}
Back to Top