Arun
Arun

Reputation: 140

Form with two submit button doesn't function properly

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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MachId :</font> 
    <input type="text" name="Text2" maxlength="15" style="height:15px; width:100px; border-color:black"><font size="2"></font>
    <font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To Date(dd/mm/yy) :</font> 
    <input type="text" name="Text4" maxlength="8" style="height:15px; width:100px; border-color:black"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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

Answers (4)

Arun
Arun

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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MachId :</font> <input type="text" name="Text2" maxlength="15"  style="height:15px; width:100px; border-color:black"><font size = "2"></font>
    <font size = "2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To Date(dd/mm/yy) :</font> <input type="text" name="Text4" maxlength="8"  style="height:15px; width:100px; border-color:black"><font size = "2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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

Barmar
Barmar

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

Brad Westfall
Brad Westfall

Reputation: 56

There are quite a few things wrong here. I'm not saying to make you feel bad, just to help.

  • In HTML, attributes should never have spaces around the equal signs. Not sure if some browsers are forgiving you for this and letting it work, but it's not standard and who knows, may be the cause of some of the issues
    • Never use the <font> element as it is obsolete https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font Strive to use CSS instead
    • You should almost never need the &nbsp; entity, strive to use CSS instead
    • Until you get more experienced, strive to never use inline styles (that's the style attribute in your HTML). Strive to use external CSS instead
    • You should use elements instead of <input type="submit"> as it is more semantic

Honestly, 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

Mark
Mark

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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MachId :</font> <input type="text" name="Text2" maxlength="15"  style="height:15px; width:100px; border-color:black"><font size = "2"></font>
<font size = "2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To Date(dd/mm/yy) :</font> <input type="text" name="Text4" maxlength="8"  style="height:15px; width:100px; border-color:black"><font size = "2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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

Related Questions