title: submit form data in html and send to server
body: <pre><code>&lt;form id="myform"&gt;&lt;label for="name"&gt;Username:&lt;/label&gt;
  &lt;input type="text" id="username" name="username"&gt;
  &lt;button id= "btnsub" onclick="registerUser();"&gt;Register&lt;/button&gt;&lt;/form&gt;
  &lt;script&gt; 
  var url="http://localhost/rrrr/register.php?username="+ username;
  var username ;      
  function registerUser()
  { 
            document.getElementById("myform").action=url;
            alert("btn click") ;
            alert(username+'');
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I tried above code, button click displays alert box as undefined what is the problem ? </p>