title: Simple JavaScript string variable returning "undefined"
body: <p>I'm basically trying to create a url friendly query string with user input. The variables replace spaces and @s and add it all together and then the function should display the url in the paragraph. This is making me feel really stupid because I know it's something really simple I'm messing up. Please point out my mistake. And as a side note, is there a better way to do all this replacing without all the variables?</p>
  
  <p>The following code should return a string similar to:
  <strong>https://www.somewebsite.com/formhandler.php?&amp;fname=gordie&amp;address=123+main+street&amp;email=something%40somewhere.com</strong></p>
  
  <pre><code>&lt;SCRIPT TYPE="TEXT/JAVASCRIPT"&gt;
  
  var fnstr = document.getElementById("firstname").value; 
  var fncutspace = fnstr.trim();
  var fnrepspace = fncutspace.replace(/ /g,"+");
  var fnfinal = fnrepspace.replace("@","%40");
  var adstr = document.getElementById("address").value; 
  var adcutspace = adstr.trim();
  var adrepspace = adcutspace.replace(/ /g,"+");
  var adfinal = adrepspace.replace("@","%40");
  var emstr = emdocument.getElementById("firstname").value; 
  var emcutspace = emstr.trim();
  var emrepspace = emcutspace.replace(/ /g,"+");
  var emfinal = emrepspace.replace("@","%40");
  var domurl = "https://www.somewebsite.com/formhandler.php?&amp;fname=";
  var secondchunk = "&amp;address=";
  var thirdchunk = "&amp;email=";
  var url = domurl + fnfinal + secondchunk + adfinal + thirdchunk + emfinal;
  
  function createurl() {
  document.getElementById("demo").innerHTML = url;
  }
  &lt;/SCRIPT&gt;
  
  &lt;FORM action="javascript:createurl()"&gt;
  Fisrt Name:&lt;INPUT id="firstname" TYPE="TEXT"&gt;&lt;br&gt;
  street address:&lt;INPUT id="address" TYPE="TEXT"&gt;&lt;br&gt;
  email address:&lt;INPUT id="email" TYPE="TEXT"&gt;&lt;br&gt;
  &lt;input type="submit" value="GO"&gt;
  &lt;/FORM&gt;
  
  &lt;p id="demo"&gt;&lt;/p&gt;
  </code></pre>