2 buttons in a html form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alien
    New Member
    • Sep 2007
    • 61

    2 buttons in a html form

    Hi guys,

    I got a html form which calls itself when clicked:

    Code:
    <% 
    	// This code deals state ADD_MORE_TRACKS
    	if(state == ADD_MORE_TRACKS || state == -1)
    	{
    		out.println("Please add your track listing");
    %>
    <form method="post" action="input.jsp">
    	<table>
    		<tr><td>Track Name:</td> <td><input type="text" name="title" size="20"></td></tr>
    		<tr><td>Track Time:   </td> <td><input type="text" name="time" size="20"></td></tr>
    		<tr><td>Track Rating:   </td> <td><input type="text" name="rating" size="20"></td></tr>
    		<tr><td><input type="submit" name = "moreElement" value="Add More Element"></td> <td><input type="button" name="finishedButton" value="Finish"></td>  </tr>
    	</table>
    </form>
    <% }	
    %>
    The form has 2 button. One is "submit" which when clicked will get the values from the textfiled and pass it onto my variables I declared above (not shown in the code above), however when i click on my 2nd button, it should let me change state so I can process what I have entered.

    I just want to know how i can get to know when the 2nd "finished" button has been clicked in jsp.

    Thanks heaps.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    You are going about JSPs the wrong way.
    You should have no Java code inside JSPs these days.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      You need to use the Request Object.

      The Request Object contains information about the page request... It is to get the values that the client passes to the web server during an HTTP request.

      The Request Object will tell you which button caused the page to submit. You do this using the Request Object's getParameter() method.

      For example:
      Code:
          if( request.getParameter( "moreElement" ) != null ) {
              // they clicked moreElement
          } else if( request.getParameter( "moreElement" ) != null ) {
              // they clicked moreElement
          }

      Comment

      Working...