Java Tutorial/JSP/Form Button
Версия от 17:44, 31 мая 2010; (обсуждение)
Содержание
Get Form Button Value
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>
Handle Form Button Action
<HTML>
<HEAD>
<TITLE>Submitting a Form</TITLE>
</HEAD>
<BODY>
<H1>Submitting a Form</H1>
<FORM NAME="form1" ACTION="basic.jsp" METHOD="POST">
<INPUT TYPE="SUBMIT" VALUE="Click Me!">
</FORM>
</BODY>
</HTML>
Using a Reset Button
<HTML>
<HEAD>
<TITLE>Using a Reset Button</TITLE>
</HEAD>
<BODY>
<H1>Using a Reset Button</H1>
<FORM ACTION="yourJSP.jsp" METHOD="POST">
Please enter your name:
<INPUT TYPE="TEXT" NAME="text1">
<BR>
<INPUT TYPE="SUBMIT" value="Submit">
<INPUT TYPE="RESET" value="Reset">
</FORM>
</BODY>
<HTML>
Using Form Button
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>