Reputation: 140
I am developing a web application and I have designed a form in my jsp page. I have some text fields and two submit buttons "send" and "search".I want my form to perform two different action when these buttons are pressed.But my action on click of search button is same as click of send button please help me on this. Below is part of my code.
<form name="Field_Details" action="ServletApp" method="get">
<fieldset style="float: center; width:920px; height: 75px;background-color:ivory; border-color:black;">
<font size="2"> MachId :</font>
<input type="text" name="Text2" maxlength="15" style="height:15px; width:100px; border-color:black"><font size="2"></font>
<font size="2"> From Date(dd/mm/yy) :</font>
<input type="text" name="Text3" maxlength="8" style="height:15px; width:100px; border-color:black"><font size="2"></font>
<font size="2"> To Date(dd/mm/yy) :</font>
<input type="text" name="Text4" maxlength="8" style="height:15px; width:100px; border-color:black"><font size="2"> </font>
<input type="submit" value="Search" style="height:30px; width:80px; formaction="FirstServlet"/><br><br>
<font size = "2">Output Field :</font> <input type="text" name="Text1" maxlength="50" style="height:15px; width:100px; border-color:black"><font size = "2"></font>
<input type= "submit" value="Send" style="height:30px; width:80px; margin-left:15px">
Upvotes: 0
Views: 69
Reputation: 140
This below code worked fine for me
<form name = "Field_Details" action="ServletApp" method= "get">
<fieldset style="float: center; width:920px; height: 75px;background-color:ivory; border-color:black;">
<font size = "2"> MachId :</font> <input type="text" name="Text2" maxlength="15" style="height:15px; width:100px; border-color:black"><font size = "2"></font>
<font size = "2"> From Date(dd/mm/yy) :</font> <input type="text" name="Text3" maxlength="8" style="height:15px; width:100px; border-color:black"><font size = "2"></font>
<font size = "2"> To Date(dd/mm/yy) :</font> <input type="text" name="Text4" maxlength="8" style="height:15px; width:100px; border-color:black"><font size = "2"> </font>
<input type="submit" value="Search" style="height:30px; width:80px;" onclick='this.form.action="FirstServlet";'/><br><br>
<font size = "2">Output Field :</font> <input type="text" name="Text1" maxlength="50" style="height:15px; width:100px; border-color:black"><font size = "2"></font>
<input type= "submit" value="Send" style="height:30px; width:80px; margin-left:15px";/>
you can just write this for submit button.I have used this only for one submit button because I wanted my second submit buttons action same as the form action.
<input type="submit" value="Search" style="height:30px; width:80px;" onclick='this.form.action="FirstServlet";'/><br><br>
Upvotes: 0
Reputation: 780974
You have a typo in the first submit button, you're missing the quotes at the end of the style
attribute. So formaction
is being seen as part of the style
, not a separate attribute.
<input type="submit" value="Search" style="height:30px; width:80px;" formaction="FirstServlet"/><br><br>
Upvotes: 2
Reputation: 56
There are quite a few things wrong here. I'm not saying to make you feel bad, just to help.
<font>
element as it is obsolete https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font Strive to use CSS instead
entity, strive to use CSS instead<input type="submit">
as it is more semanticHonestly, none of these things are necessarily the reason why the code is not working, but the way you have this written makes it pretty difficult for others to look at and evaluate what's going on to help you
Upvotes: 0
Reputation: 89
<form name = "Field_Details" action = "ServletApp" method= "get">
<fieldset style="float: center; width:920px; height: 75px;background-color:ivory; border-color:black;">
<font size = "2"> MachId :</font> <input type="text" name="Text2" maxlength="15" style="height:15px; width:100px; border-color:black"><font size = "2"></font>
<font size = "2"> From Date(dd/mm/yy) :</font> <input type="text" name="Text3" maxlength="8" style="height:15px; width:100px; border-color:black"><font size = "2"></font>
<font size = "2"> To Date(dd/mm/yy) :</font> <input type="text" name="Text4" maxlength="8" style="height:15px; width:100px; border-color:black"><font size = "2"> </font>
<input type= "submit" value="Search" onclick="submitForm('FirstServlet');" style="height:30px; width:80px; formaction="FirstServlet"/><br><br>
<font size = "2">Output Field :</font> <input type="text" name="Text1" maxlength="50" style="height:15px; width:100px; border-color:black"><font size = "2"></font>
<input type= "submit" value="Send" onclick="submitForm('ServletApp');" style="height:30px; width:80px; margin-left:15px">
Upvotes: -1