title: Unable to update value in a form and send to next jsp page
body: <p>I have a form and trying to change a value in a hidden input element prior to submitting the data to another JSP file(db.jsp) for processing. Different value is stored depending on which button is clicked. But the change doesn't occur and the value is always sent over as the default value "abc" to the db.jsp file. </p>
  
  <p>Form Page (index.jsp) and Javascript to change value depending on</p>
  
  <pre><code>&lt;form method="post" action="db.jsp"&gt;
      &lt;div class="form-group col-sm-3 col-lg-3"&gt;
          &lt;button id="update" type="submit" &gt;Update&lt;/button&gt;
          &lt;button id="delete" type="submit" &gt;Delete&lt;/button&gt;
          &lt;input id="secret2" name="secret2" value="abc" type="hidden"&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  
  &lt;script&gt;
      $("#delete").click(function(){
          //tried calling an alert here and no alert shows up. 
          document.getElementById("#secret2").value = "delete";
      });
      $("#update").click(function(){
          //tried calling an alert here and no alert shows up. 
          document.getElementById("#secret2").value = "update";
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>db.jsp</p>
  
  <pre><code>&lt;%
      String buttonId = request.getParameter("secret2");
      System.out.println(buttonId); //prints as "abc"
  %&gt;
  </code></pre>
  
  <p><strong>More Details on first Page Body (index.jsp):</strong> </p>
  
  <pre><code>&lt;script&gt;
          $(document).ready(function() {
              $("#delete").click(function(){
                  document.getElementById("secret2").value = "delete";
              });
              $("#update").click(function(){
                  document.getElementById("secret2").value = "update";
              });
          });
  &lt;/script&gt;
  &lt;body&gt;
      &lt;h1 class="k-h1-view-user"&gt;Users&lt;/h1&gt;
  
      &lt;%
          String dbURL = "jdbc:mysql://1.1.1.1:3306/db_name";
          String dbUser = "";
          String dbPass = "";
          Connection conn;
  
          try{
              DriverManager.registerDriver(new com.mysql.jdbc.Driver());
              conn = DriverManager.getConnection(dbURL, dbUser, dbPass);
  
              Statement statement = conn.createStatement();
              ResultSet resultset =
                      statement.executeQuery("select id, username, password, role from user");
  
              while(resultset.next()) {
      %&gt;
  
      &lt;form class="k-view-user-form k-form-margin-top" method="post" action="delete_user.jsp"&gt;
          &lt;div class="form-group col-sm-3 col-lg-3"&gt;
              &lt;input value="&lt;%= resultset.getString(2) %&gt;" type="text" class="form-control" id="usernameField" name="usernameField" placeholder="Username" style="margin: 0 auto"&gt;
          &lt;/div&gt;
          &lt;div class="form-group col-sm-3 col-lg-3"&gt;
              &lt;input value="&lt;%= resultset.getString(3) %&gt;" type="password" class="form-control" id="passwordField" name="passwordField" placeholder="Password" style="margin: 0 auto"&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group col-sm-3 col-lg-3"&gt;
              &lt;select class="form-control" id="role" name="role" style="margin: 0 auto"&gt;
                  &lt;%
                      if(resultset.getString(4).equals("admin")){
                  %&gt;
                      &lt;option value="admin" selected&gt;Admin&lt;/option&gt;
                      &lt;option value="standard"&gt;Standard&lt;/option&gt;
                  &lt;%
                      }
                      else{
                  %&gt;
                      &lt;option value="admin"&gt;Admin&lt;/option&gt;
                      &lt;option value="standard" selected&gt;Standard&lt;/option&gt;
                  &lt;%
                      }
                  %&gt;
              &lt;/select&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group col-sm-3 col-lg-3"&gt;
              &lt;button id="update" type="submit" class="btn k-login-btn" style="float: left"&gt;Update&lt;/button&gt;
              &lt;button id="delete" type="submit" class="btn k-del-btn" style="float: right"&gt;Delete&lt;/button&gt;
              &lt;input name="secret" value="&lt;%= resultset.getString(1) %&gt;"  type="hidden"&gt;
              &lt;input id="secret2" name="secret2" type="hidden"&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  
      &lt;%}
  
      }catch (Exception e){
          e.printStackTrace();
      }
  
      %&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/0AvEx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0AvEx.jpg" alt="enter image description here"></a></p>