title: Taking input and updating a div tag using javascript and html
body: <p>Ok so I have to make a basic javascript file that takes data from two input fields and then updates the div tag with the relevant new values when a button is clicked. This is the first thing I have ever done in JS, so excuse any bad practices. I have 3 buttons, the first two save and update only the name or the age respectively. The third one creates a new object "init" and saves and updates both. I wish I could tell you more about what is wrong, but nothing changes when I click any of the buttons so I have no idea.</p>
  
  <p>Thanks for the help</p>
  
  <p>Here is my HTML:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form name="inForm"&gt;
              &lt;input type="text" name="user"/&gt;
              &lt;input type="text" name="age"/&gt;
          &lt;/form&gt;
      &lt;button onClick="User.setName"&gt; Save name &lt;/button&gt;
      &lt;button onClick="User.setAge"&gt; Save age &lt;/button&gt;
      &lt;button onClick="writeIn"&gt; Save &lt;/button&gt;
      &lt;div id="update"&gt;
      &lt;/div&gt;
             &lt;script language="JavaScript1.2" src="script.js" type="text/javascript"/&gt;
      &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>And here is my javascript:</p>
  
  <pre><code>var User = function() {
      var save = function(callback) {
          if (callback) {
              callback();
          }
      }
  
      return {
          name: function() {
              write = document.getElementById('update');
              write.innerHTML = this.name;
              return this.name;
          }(),
          age: function() {
              write = document.getElementById('update');
              write.innerHTML = this.age;
              return this.age;
          }(),
          setName: function() {
              this.name = document.inForm.name;
          },
          setAge: function() {
              this.age = document.inForm.age;
          },
          save: save,
          init: function(name, age) {
              this.name = name;
              this.age = age;
              write = document.getElementById('update');
              write.innerHTML = this.age + this.name;
              return this;
          }
      };
  };
  
  function writeIn() {
      var a = new User
      a.init(document.inForm.name, document.inForm.age)
  }
  
  console.log(a.name, b.name);
  </code></pre>