title: How to use of document.getElementById
body: <p>In my JSP page I have a form for login with two text boxes with name and id as "u" for username and "p" for password. I take in the values as </p>
  
  <p>var user=document.getElementById("u").value;</p>
  
  <p>var pass=document.getElementById("p").value;</p>
  
  <p>When the first user of the application tries to login with user as user1 and pass as pass1. This value is passed to the admin.java which gets the values by using request.getParameter.</p>
  
  <p>This is all fine.After the first user logs out. And another user tries to login again using the authetication user as user2 and pass as pass2 the problem is the variable user and pass in the index.jsp retain the same old values of user1 and pass1. I checked these through alert boxes. The same values are passed to Admin.java.</p>
  
  <p>The code in index.jsp is</p>
  
  <pre><code>    function prepareLoginDialog(){
      $dialog = $('&lt;div&gt;&lt;/div&gt;')
      .html('&lt;div id="dialog-confirm" title="Enter the login details here :"&gt;'+
          'User: &lt;input type="text" id="u" name="u" &gt;&lt;/input&gt;&lt;br /&gt;'+
          'Pass: &lt;input type="password" id="p" name="p" &gt;&lt;/input&gt;'+
          '&lt;/div&gt;')
  
          //System.out.println(user);
      //System.out.println(pass);
      .dialog({
          autoOpen: false,
          modal: true,
          title: 'Login',
          buttons: {
              'Login': function() {
                  //Send Login Request to Server
                  alert("I in login");
  
                  var user = document.getElementById("u").value;
                  var pass = document.getElementById("p").value;
                  alert(user);
                  alert(pass);
                  //System.out.println(u.text);
                  login(user,pass);
  
                  $(this).dialog('close');
              },
              Cancel: function() {
                  $(this).dialog('close');
              }
          }
      });
  
      $('#login').click(function() {
          $dialog.dialog('open');
          // prevent the default action, e.g., following a link
          return false;
      });
  }
  </code></pre>
  
  <p>Why is the new value not taken in the two variables? Where have I gone wrong?</p>