Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi All,

I want to know whether is it possible to have two buttons in a single form, which hits two different servlets.
I have googled about it and some of the solution says is it possible by giving form_name.action in a javascript function. I tried doing this but dint succeed.
function doSumthing(){
document.formName.action='servletPath';
}

Also if somebody could tell me what is the servlet path.

If somebody could help me on the same.

Thanks in advance,
Kejal
Posted
Updated 1-Jun-11 4:00am
v2
Comments
Steven.Pinto2000 1-Jun-11 10:22am    
create two form tags and put the action attribute on each of those tags

1 solution

Try this:

HTML
<HTML>
    <HEAD>
        <TITLE>Using Buttons</TITLE>
    </HEAD>

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

        <SCRIPT LANGUAGE="JavaScript">
            <!--
               function button1()
               {
                   document.form1.ACTION = "option1.jsp"
                   form1.submit()
               }
               function button2()
               {
                   document.form1.ACTION = "option2.jsp"
                   form1.submit()
               }
            // -->
        </SCRIPT>
    </BODY>
</HTML>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900