title: Javascript Var Scope Help
body: <p>This is my code, I fear that some of the variables are not being scoped properly.      </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8" /&gt;
          &lt;title&gt;Memory Test&lt;/title&gt;
          &lt;link href="bio.css" rel="stylesheet" type="text/css"&gt;
          &lt;script src="../jquery-1.5.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body onLoad="timeMsg()"&gt;
          &lt;div id="container"&gt;
              &lt;h3&gt;The numbers are...&lt;/h3&gt;
              &lt;input id="number" type="text" value="495"/&gt;
              &lt;div id="remember"&gt;
  
              &lt;/div&gt;
              &lt;div id="email"&gt;
                  &lt;input id="a"&gt;&lt;/input&gt;
                  &lt;input id="b"&gt;&lt;/input&gt;
                  &lt;input id="c"&gt;&lt;/input&gt;
                  &lt;input id="d"&gt;&lt;/input&gt;
                  &lt;input id="e"&gt;&lt;/input&gt;
                  &lt;input id="f"&gt;&lt;/input&gt;
                  &lt;input id="g"&gt;&lt;/input&gt;
                  &lt;input id="h"&gt;&lt;/input&gt;
                  &lt;input id="i"&gt;&lt;/input&gt;
              &lt;/div&gt;
              &lt;script&gt;
              var a = document.getElementById("a").value;
              var b = document.getElementById("b").value;
              var c = document.getElementById("c").value;
              var d = document.getElementById("d").value;
              var e = document.getElementById("e").value;
              var f = document.getElementById("f").value;
              var g = document.getElementById("g").value;
              var h = document.getElementById("h").value;
              var i = document.getElementById("i").value;
  
  
              function timeMsg()
              {
              var t=setTimeout("alertMsg()",500);
              }
              function alertMsg()
              {
                  document.getElementById('remember').innerHTML = ('&lt;h3&gt;Times up partner, what were they?&lt;/h3&gt;&lt;/br&gt;&lt;input name="one" id="one" type="text"&gt;&lt;/input&gt;&lt;/br&gt;&lt;input id="answer" type="button" value="Next" onClick="changeSet()"/&gt;');
                  document.getElementById('number').value = 'no cheating...';
                  }
  
              function changeSet() {
                  var s=setTimeout("alertYea()",500);
                  var a = document.getElementById('a').innerHTML = (document.getElementById("one").value);
                  document.getElementById('remember').innerHTML = ('&lt;p id="bumper"&gt;2&lt;/p&gt;');
                  document.getElementById('number').value = '9264';
              }
              function alertYea() {
                  document.getElementById('remember').innerHTML = ('&lt;h3&gt;Times up partner, what were they?&lt;/h3&gt;&lt;/br&gt;&lt;input name="two" id="two" type="text"&gt;&lt;/input&gt;&lt;/br&gt;&lt;input id="answer" type="button" value="Next" onClick="changeSet2()"/&gt;');
                  document.getElementById('number').value = 'no cheating...';
  
                  }
  
              function changeSet2() {
                  var a=setTimeout("alertYea2()",500);
                  var b = document.getElementById('b').innerHTML = (document.getElementById("two").value);
                  document.getElementById('remember').innerHTML = ('&lt;p id="bumper"&gt;3&lt;/p&gt;');
                  document.getElementById('number').value = '38671';
              }
  
              function alertYea2() {
                  document.getElementById('remember').innerHTML = ('&lt;h3&gt;Times up partner, what were they?&lt;/h3&gt;&lt;/br&gt;&lt;input name="three" id="three" type="text"&gt;&lt;/input&gt;&lt;/br&gt;&lt;input id="answer" type="button" value="Next" onClick="changeSet3()"/&gt;');
                  document.getElementById('number').value = 'no cheating...';
  
                  }
  
              function changeSet3() {
                  var a=setTimeout("alertYea3()",500);
                  var c = document.getElementById('c').innerHTML = (document.getElementById("three").value);
                  document.getElementById('remember').innerHTML = ('&lt;p id="bumper"&gt;4&lt;/p&gt;');
                  document.getElementById('number').value = '938263';
              }
  
              function alertYea3() {
                  document.getElementById('remember').innerHTML = ('&lt;h3&gt;Times up partner, what were they?&lt;/h3&gt;&lt;/br&gt;&lt;input name="four" id="four" type="text"&gt;&lt;/input&gt;&lt;/br&gt;&lt;input id="answer" type="button" value="Next" onClick="changeSet4()"/&gt;');
                  document.getElementById('number').value = 'no cheating...';
  
                  }
  
              function changeSet4() {
                  var a=setTimeout("alertYea4()",500);
                  var d = document.getElementById('d').innerHTML = (document.getElementById("four").value);
                  document.getElementById('remember').innerHTML = ('&lt;p id="bumper"&gt;5&lt;/p&gt;');
                  document.getElementById('number').value = '8351032';
              }
  
              function alertYea4() {
                  document.getElementById('remember').innerHTML = ('&lt;h3&gt;Times up partner, what were they?&lt;/h3&gt;&lt;/br&gt;&lt;input name="five" id="five" type="text"&gt;&lt;/input&gt;&lt;/br&gt;&lt;input id="answer" type="button" value="Next" onClick="changeSet5()"/&gt;');
                  document.getElementById('number').value = 'no cheating...';
  
                  }
  
              function changeSet5() {
                  var a=setTimeout("alertYea5()",500);
                  var e = document.getElementById('e').innerHTML = (document.getElementById("five").value);
                  document.getElementById('remember').innerHTML = ('&lt;p id="bumper"&gt;6&lt;/p&gt;');
                  document.getElementById('number').value = '02619815';
              }
  
              function alertYea5() {
                  document.getElementById('remember').innerHTML = ('&lt;h3&gt;Times up partner, what were they?&lt;/h3&gt;&lt;/br&gt;&lt;input name="six" id="six" type="text"&gt;&lt;/input&gt;&lt;/br&gt;&lt;input id="answer" type="button" value="Next" onClick="changeSet6()"/&gt;');
                  document.getElementById('number').value = 'no cheating...';
  
                  }
  
              function changeSet6() {
                  var a=setTimeout("alertYea6()",500);
                  var f = document.getElementById('f').innerHTML = (document.getElementById("six").value);
                  document.getElementById('remember').innerHTML = ('&lt;p id="bumper"&gt;7&lt;/p&gt;');
                  document.getElementById('number').value = '274619523';
              }
  
              function alertYea6() {
                  document.getElementById('remember').innerHTML = ('&lt;h3&gt;Times up partner, what were they?&lt;/h3&gt;&lt;/br&gt;&lt;input name="seven" id="seven" type="text"&gt;&lt;/input&gt;&lt;/br&gt;&lt;input id="answer" type="button" value="Next" onClick="changeSet7()"/&gt;');
                  document.getElementById('number').value = 'no cheating...';
  
                  }
  
              function changeSet7() {
                  var a=setTimeout("alertYea7()",500);
                  var g = document.getElementById('g').innerHTML = (document.getElementById("seven").value);
                  document.getElementById('remember').innerHTML = ('&lt;p id="bumper"&gt;8&lt;/p&gt;');
                  document.getElementById('number').value = '1681324849';
              }
  
              function alertYea7() {
                  document.getElementById('remember').innerHTML = ('&lt;h3&gt;Times up partner, what were they?&lt;/h3&gt;&lt;/br&gt;&lt;input name="eight" id="eight" type="text"&gt;&lt;/input&gt;&lt;/br&gt;&lt;input id="answer" type="button" value="Next" onClick="changeSet8()"/&gt;');
                  document.getElementById('number').value = 'no cheating...';
  
                  }
  
              function changeSet8() {
                  var a=setTimeout("alertYea8()",500);
                  var h = document.getElementById('h').innerHTML = (document.getElementById("eight").value);
                  document.getElementById('remember').innerHTML = ('&lt;p id="bumper"&gt;9&lt;/p&gt;');
                  document.getElementById('number').value = '48372605629';
                  emailData.data.value = h;
              }
  
              function alertYea8() {
                  document.getElementById('remember').innerHTML = ('&lt;h3&gt;Times up partner, what were they?&lt;/h3&gt;&lt;/br&gt;&lt;input name="nine" id="nine" type="text"&gt;&lt;/input&gt;&lt;/br&gt;&lt;p id="send"&gt;&lt;/p&gt;&lt;input id="answer" name="submit" type="button" onclick="finals()" value="Next"/&gt;');
                  document.getElementById('number').value = 'no cheating...';
  
                  }
              function finals() {
                  var i = document.getElementById('i').innerHTML = (document.getElementById("nine").value);
                  document.getElementById('remember').innerHTML = ('&lt;div id="send"&gt;&lt;form action="mailto:hubridnoxx@gmail.com" method="POST" enctype="text/plain" name="emailData"&gt;&lt;/br&gt;&lt;input id="data" type="text" size="20" name="data"&gt;&lt;br&gt;&lt;input type="submit" value="Submit and continue to letters!"&gt;&lt;/form&gt;&lt;/div&gt;');
  
                  emailData.data.value = a + b + c + d + e + f + g + h + i;
                  var total= 0;
                  $('input', '#email').each(function () {
                      total += parseInt($(this).val());
                  });
                  emailData.data.value = total;
                  }
              &lt;/script&gt;
  
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem lies in the last line,</p>
  
  <p>emailData.data.value = a + b + c + d + e + f + g + h + i;
  The page only returns the value of input id i, not input ids a-h. Instead, it displays like tons of [object HTMLInputElement] for each input id value. I'm even calling .value. How can I fix this so that</p>
  
  <p>emailData.data.value = a + b + c + d + e + f + g + h + i;
  displays a set of respective values instead?</p>