title: Storing HTML Form input as an Object using a Constructor class and a dynamic variable name (Plain JS)
body: <pre><code>&lt;form id="projectForm" onsubmit="return ptitle.value = new Project(this);"&gt;
                  &lt;div class="form-row"&gt;
                  &lt;label for="ptitle"&gt;Title: &lt;/label&gt;
                  &lt;input type="text" id="ptitle" name="ptitle"&gt;&lt;br&gt;
                  &lt;/div&gt;
                  &lt;div class="form-row"&gt;
                  &lt;label for="pdescription"&gt;Discription: &lt;/label&gt;
                  &lt;input type="text" id="pdescription" name="pdescription"&gt;&lt;br&gt;
                  &lt;/div&gt;
                  &lt;div class="form-row"&gt;
                  &lt;label for="pdueDate"&gt;Due Date&lt;/label&gt;
                  &lt;input type="date" id="pdueDate" name="pdueDate"&gt;&lt;br&gt;
                  &lt;/div&gt;
                  &lt;div class="form-row"&gt;
                  &lt;label for="high"&gt;High&lt;/label&gt;
                  &lt;input type="radio" id="high" name="priority"&gt;
                  &lt;label for="low"&gt;Low&lt;/label&gt;
                  &lt;input type="radio" id="low" name="priority"&gt;&lt;br&gt;
                  &lt;input id="submit" type="submit" value="submit"&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>So I would like to take the data submitted from this form and call a constructor method within the Projects class. I'd also like to  be able to dynamically generate the variable name from the title value of the form. Here's the JavaScript code. I'll need to use plain JS as that is what's required for the project! We're also required to use a constuctor class or factory function to generate the projects. As you can see I've tried to take a stab at it but unfortunately it hasn't worked. Thanks in advance.</p>
  
  <pre><code>class Project {
  
  
      constructor(form) {
          this.title = form.ptitle.value;
          this.description = form.pdescription.value;
          this.dueDate = form.pdueDate.value;
          this.priority = form.priority.value;
      }
  
      todoList = {};
  
      addTodoList(value, description) {
  
          this.todoList[value] = description;
      }
  
      removeTodoList(key) {
          delete this.todoList[key];
      }
  
  }
  </code></pre>
  
  <p>Thanks again!!!</p>