title: How to set the value of a div
body: <p>I am in the process of writing a small quiz app and am looking at different ways of setting the value of a div or text field</p>
  
  <p>As a learning process, I have attempted to set the value of page elements using a number of different methods</p>
  
  <ol>
  <li>document.form1.questionDisplay.value = VALUE// This works - I'm targeting a textarea by "name"</li>
  <li><p>document.getElementById("showQuestion2").innerHTML = VAULE //This works using the getElementById method.</p></li>
  <li><p>document.showQuestion3.value=   allQuestions[2].question+"\n"+allQuestions[2]
  THIS is doesnt work. this returns - TypeError: document.showQuestion3 is undefined.  Is my    mistake:
  a. misunderstanding the syntax document.element_name.value is just plain incorrect</p></li>
  <li>document.showQuestion3.innerHTML= allQuestions[2].question+"\n"+allQuestions[2]….
   this returns - document.showQuestion3 is undefined</li>
  </ol>
  
  <p>What I am attempting to confirm is:</p>
  
  <p>When using forms, you can navigate the DOM/BOM via the name property to set/retrieve values</p>
  
  <p>When attempting to change/set the HTML of an element, you cannot use the nomenclature:
   document.ID.innerHTML - you need to use the getElementbyID method, there is no way to do it otherwise</p>
  
  <p><strong>SAMPLE/EXPERIMENTAL CODE</strong></p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
  
                  function btnShowQuestion_onclick(){
                      var allQuestions = [
                          {question: "Who is Prime Minister of the United Kingdom?",
                          choices: ["David Cameron", "Gordon Brown", "Winston Churchill", "Tony Blair"],
                          correctAnswer:0},
                          {question: "What is Superman's real name?",
                          choices: ["Carmen Electra", "Gordon Brown", "Clark Kent", "Tony Blair"],
                          correctAnswer:2},
  
                          {question: "What if god was one of us?",
                          choices: ["would he be a stranger on the bus", "Would he be a cat ", "she would do a duet with britney spears", "it would smite you dead"],
                          correctAnswer:2}
                      ];
  
                      document.form1.questionDisplay.value = allQuestions[0].question+"\n"+allQuestions[0].choices+"\n";
                      document.getElementById("showQuestion2").innerHTML = allQuestions[1].question+"\n"+allQuestions[1].choices+"\n";
                      document.showQuestion3.value= allQuestions[2].question+"\n"+allQuestions[2].choices+"\n";
                  };
  
  
              &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
          &lt;div class="row"&gt;
       &lt;div class="col-md-12"&gt;
  
             &lt;h1&gt;Let' play a game&lt;/h1&gt;
  
              &lt;div id="showQuestion2"&gt;&lt;/div&gt;
               &lt;div name="showQuestion3"&gt;&lt;/div&gt;
              &lt;form name="form1" action=""&gt;
              &lt;textarea rows="10" cols="35" name="questionDisplay"&gt;&lt;/textarea&gt;
              &lt;br /&gt;
              &lt;input type="button" value="show question" name="btnShowVisited" onclick="btnShowQuestion_onclick()" /&gt;
              &lt;/form&gt;
  
  
        &lt;/div&gt;
        &lt;/div&gt;
  </code></pre>