title: how to get value from url parameter using javascript or jquery
body: <p>I have an issue in getting value from url, I have a link which shows up a modal
  as I have</p>
  
  <pre><code>&lt;a href='#modal?userId=&lt;%=resultSet.getInt("drid")%&gt;' class="button-border toggleModal"&gt;Apportionment&lt;/a&gt;
  </code></pre>
  
  <p>above link opens up the modal is given below</p>
  
  <pre><code>&lt;div id="modal" class="modal"&gt;    
      &lt;header&gt;
        &lt;h2&gt;Appointment Form&lt;/h2&gt;      
      &lt;/header&gt;
      &lt;form action="addappoinment.jsp" method="post"&gt;
          &lt;input type="hidden" id="docId" name="docid" value=""&gt;&lt;br&gt;
          &lt;input type="text" required&gt;&lt;br&gt;
          &lt;input type="text" required&gt;&lt;br&gt;
          &lt;input type="text" required&gt;&lt;br&gt;
          &lt;input type="text" required&gt;&lt;br&gt;
          &lt;textarea rows="4" cols="21"&gt;&lt;/textarea&gt;&lt;br&gt; 
          &lt;button class="button-border button-success" type="submit"&gt;
       Done&lt;/button&gt;
  
      &lt;button class="button-border button-error pull-right toggleModal"&gt;
        Cancel&lt;/button&gt;       
        &lt;/form&gt;    
    &lt;/div&gt;
  </code></pre>
  
  <p>Now I have a url like </p>
  
  <pre><code>http://localhost:8080/app/#modal?userId=1
  </code></pre>
  
  <p>now I want to get value of <code>userId</code> parameter using the javascript </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  function getParameterByName(name) {
      name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
      var regex = new RegExp("[\\?&amp;]" + name + "=([^&amp;#]*)"),
          results = regex.exec(location.search);
      return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  }
  
  var param = getParameterByName("userId");
  var userId = document.getElementById("docId");
  userId.value = param;
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>but can not be able to get value from <code>http://localhost:8080/app/#modal?userId=1</code></p>