0

G'day,

My problem is not one that is overly complex but i have been unable to find a simple solution to my problem.

My problem is that i have my given form with two submit buttons, for which I'm using images. Once i click on the images, how do i check which image (button) has been clicked?

My form is as follows:

<table width='50%' border='0' align='center'>
    <tr align='center'>
        <td>Attraction</td>
        <td>Adult Price</td>
        <td>Child Price</td>
        <td>Location</td>
    </tr>
    
    <form action="addAttractions.jsp" method="post">
        <% out.println(tr); %>  // Outputs table rows of given data
        <tr>
            <td>
                 <input type="image" name ="Update" src="Images/b_edit.png" alt="Submit button1">
                  <input type="image" name ="Delete" src="Images/b_delete.png" alt="Submit button2">
            </td>
        </tr>
     </form>
</table>

I'm unsure how to get the param value for the image which was clicked.

Your appreciation would be much appreciated.


Regards,
TC

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by ~s.o.s~
0

Create a hidden form field, and on clicking the button run a bit of Javascript that first sets a value to that field depending on which button it is, then submits the form.

0

Create a hidden form field, and on clicking the button run a bit of Javascript that first sets a value to that field depending on which button it is, then submits the form.

Is there another possible method as i am not very confident with using JScript??

1

Is there another possible method as i am not very confident with using JScript??

Keep the same name for both the buttons and let them have different values.

<form action="addAttractions.jsp" method="post">
        <% out.println(tr); %>  // Outputs table rows of given data
        <tr>
            <td>
                 <input type="image" name="button" value ="Update" src="Images/b_edit.png" alt="Submit button1">
                  <input type="image" name="button" value ="Delete" src="Images/b_delete.png" alt="Submit button2">
            </td>
        </tr>
     </form>

In your servlet code,

String action = request.getParameter("button");
if("Update".equals(action)) {
    System.out.println("Update clicked");
} else if("Delete".equals(action)) {
    System.out.println("Delete clicked");
}

Buuuut, there is a long standing bug in IE wherein the button value is not submitted, but rather the X and Y coordinates of the button are (LOL?). This thread describes the issue pretty well with a couple of workarounds.

Hope that helped. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.