#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    <form
    name=form1
    action="userActionServlet"
    method="post"
    >
    //...
    <input
    type=submit
    name=calculate
    value="Calculate"
    >
    <input
    type=submit
    name=save
    value=" Save "
    >

    If I intend to use my ActionServlet to
    perform both 'calculate' and 'save'
    functionalities, I need to know
    which 'submit' button is hit. So,
    How do I know which one is hit via
    the 'name' property--or some other
    way?

    Is this possible?

    OR, is it possible to associate
    two servlets to two submit-buttons
    for a single form?
    It seems CGI guys do use two named
    submit buttons with a single form.
    Am I right in this?

    Thanks in advance.



    ------------------
    Regards,
    Tony

    Comments on this post

    • JimmyGosling agrees
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Guayquil, Ecuador
    Posts
    7
    Rep Power
    0
    Hi, the best solution i can think of is manipulating the form in the client side, by doing this:
    two javascript functions to be called in the onclick event for each submit button.
    As you can imagine if you click the first button you will get some values for the form fields (using hidden fields could be good idea) and if you click the second one you get other values, doing this the servlet will "know" wich submit has been clicked.
    I think you can also select the "action" for the form dinamically with javascript, allowing this to use to different servlets.

    An example function to manipulate form values is:
    <input type=submit name=calculate value=""
    onclick=calculate()>
    <input type=submit name=save value=""
    onclick=save()>
    ....
    function calculate(){
    document.formname.calculate.value="calculate";
    //document.formname.submit
    }
    function save(){
    document.formname.save.value="save";
    //document.formname.submit
    }
    this code is not tested, but is something like that
    Bye
    Hope it helps.
    OttoX


  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    Hi Ottox,

    Thanks a lot to you for your answer which
    sparked me into yet another solution
    to my origninal question:

    if I put

    <form
    name=form1
    action="userActionServlet"
    method="POST"
    >
    //...
    <input
    type=submit
    name=submit
    value="Calculate">
    <input
    type=reset
    name=reset
    value=Reset">
    <input
    type=submit
    name=submit
    value="Save">

    then I can use

    out.prinlnt("<BR>"+req.getParameter("submit")+"<BR>"));

    to get the 'value' of the clicked submit
    button. In such way, I can know which
    submit-typed button is clicked and fire a
    corresponding action inside the
    ActionServlet.

    Thank you again, Ottox. Keep cool!


    ------------------
    Regards,
    Tony

IMN logo majestic logo threadwatch logo seochat tools logo