title: Retrieve input value from js script to django view
body: <p>I have created an html input in a js script this way:</p>
  
  <pre><code>var compte = document.createElement("input");
      compte.setAttribute("name", "compte");
  </code></pre>
  
  <p>I need to retrieve that input value into a django view. Usually, I use the name attribute of the input:</p>
  
  <pre><code>num=request.POST['compte']
  </code></pre>
  
  <p>In this case, it didn't work knowing the html input was created using javascript. So how do I get the value?</p>
  
  <p>I'm adding below the whole code. I've actually inserted a new row containing the inputs to the table.</p>
  
  <pre><code>&lt;form class="myForm" action="Plan_comptable" method='POST'
  enctype="multipart/form-data"&gt;
  
  &lt;table id="myTable" class="gtreetable table gtreetable-fullAccess"&gt;
  {% csrf_token %}
  
  &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Compte&lt;/th&gt;&lt;th&gt;Intitulé&lt;/th&gt;&lt;th&gt;&lt;/th&gt;
  &lt;/tr&gt;&lt;/thead&gt;
  
  &lt;tbody&gt;
  {% for el in ViewPC_query %}
  &lt;tr&gt;
      &lt;td&gt;{{ el.Num }}&lt;/td&gt;
      &lt;td&gt;{{ el.Intitule }}&lt;/td&gt;
  
      &lt;td width="30"&gt;
       &lt;div class="dropdown"&gt;
       &lt;button class="btn btn-primary 
       dropdown-toggle" type="button" data-toggle="dropdown"&gt;Action
       &lt;span class="caret"&gt;&lt;/span&gt;&lt;/button&gt;
  
  &lt;ul class="dropdown-menu"&gt;
    &lt;li&gt;&lt;a id="{{ forloop.counter }}" class="dropdown-item" 
    onclick="beforeFunction(this);" href="#"&gt;Créer avant&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a id="{{ forloop.counter }}" class="dropdown-item" 
     onclick="afterFunction(this);" href="#"&gt;Créer après&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a class="dropdown-item" onclick="" href="#"&gt;Créer first child&lt;/a&gt; 
     &lt;/li&gt;
    &lt;li id="actionsep"&gt;&lt;a class="dropdown-item" href="#" 
      id="actionsep"&gt;Créer last child&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a class="dropdown-item" href="Modifier_PC/{{ el.id }}"&gt;Modifier&lt;/a&gt; 
     &lt;/li&gt;
    &lt;li&gt;&lt;a class="dropdown-item" href="Supprimer_PC/{{ el.id 
      }}"&gt;Supprimer&lt;/a&gt;&lt;/li&gt;
   &lt;/ul&gt;&lt;/div&gt;&lt;/td&gt;
  
  &lt;/tr&gt;
            {% endfor %}
  
      &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  
  &lt;script&gt;
  function beforeFunction (element) {
      var myTable = document.getElementById("myTable");
      var currentRow = myTable.insertRow(element.id);
  
      var compte = document.createElement("input");
      compte.setAttribute("id", "idcompte");
      compte.setAttribute("name", "compte");
      compte.setAttribute("class", "form-control");
  
      var intitule = document.createElement("input");
      intitule.setAttribute("name", "intitule");
      intitule.setAttribute("class", "form-control");
  
      var button = document.createElement("button");
      button.setAttribute("name", "action" + element.id);
      button.setAttribute("class", "btn btn-primary dropdown-toggle");
      button.setAttribute("data-toggle", "dropdown");
      var textnode1 = document.createTextNode("Action");
      var textnode2 = document.createTextNode("Enregistrer");
      var textnode3 = document.createTextNode("Annuler");
      var span = document.createElement("span");
      span.setAttribute("class", "caret");
  
      var ul = document.createElement("ul");
      ul.setAttribute("class", "dropdown-menu");
  
      var li1 = document.createElement("li");
      var li2 = document.createElement("li");
      var Enregistrer = document.createElement("a");
      Enregistrer.setAttribute("href", "UpdatePC_before");
      var Supprimer = document.createElement("a");
      Supprimer.setAttribute("href", "{% url 'comptes' %}");
      var div = document.createElement("div");
      div.setAttribute("class", "dropdown");
  
      var currentCell = currentRow.insertCell(-1);
      currentCell.appendChild(compte);
  
      currentCell = currentRow.insertCell(-1);
      currentCell.appendChild(intitule);
  
      Enregistrer.appendChild(textnode2);
      Supprimer.appendChild(textnode3);
      li1.appendChild(Enregistrer);
      li2.appendChild(Supprimer);
      ul.appendChild(li1);
      ul.appendChild(li2);
      button.appendChild(textnode1);
      button.appendChild(span);
  
      currentCell = currentRow.insertCell(-1);
      div.setAttribute("class", "dropdown");
      div.appendChild(button);
      div.appendChild(ul);
      currentCell.appendChild(div);
  
  }
  </code></pre>