Using Form Button : Form Button « JSP « Java Tutorial






index.jsp

<HTML>
    <HEAD>
        <TITLE>Using Buttons</TITLE>
    </HEAD>
 
    <BODY>
        <H1>Using Buttons</H1>
        <FORM NAME="form1" ACTION="basic.jsp" METHOD="POST">
            <INPUT TYPE="HIDDEN" NAME="buttonName">
            <INPUT TYPE="BUTTON" VALUE="Button 1" ONCLICK="button1()">
            <INPUT TYPE="BUTTON" VALUE="Button 2" ONCLICK="button2()">
            <INPUT TYPE="BUTTON" VALUE="Button 3" ONCLICK="button3()">
        </FORM>

        <SCRIPT LANGUAGE="JavaScript">
            <!--
               function button1()
               {
                   document.form1.buttonName.value = "button 1"
                   form1.submit()
               }    
               function button2()
               {
                   document.form1.buttonName.value = "button 2"
                   form1.submit()
               }    
               function button3()
               {
                   document.form1.buttonName.value = "button 3"
                   form1.submit()
               }    
            // --> 
        </SCRIPT>
    </BODY>
</HTML>

basic.jsp

<HTML>
    <HEAD>
        <TITLE>Determining Which Button Was Clicked</TITLE>
    </HEAD>
 
    <BODY>
        <H1>Determining Which Button Was Clicked</H1>
        You clicked 
        <%= request.getParameter("buttonName") %>
    </BODY>
</HTML>
  Download:  UsingFormButton.zip( 1 k)








23.16.Form Button
23.16.1.Using Form Button
23.16.2.Handle Form Button Action
23.16.3.Get Form Button Value
23.16.4.Using a Reset Button