views:

29

answers:

2

I have a jsp file in which I have a form. It shows data about an "account" data structure we have. There's a button to remove the data from that data structure.

<form action="removeThisData.html" method="post">
  ... blah blah blah ...
  <input type="submit" value="Remove"/>
</form>

Now, there's a component that I want to be editable. Basically, I want that third blah to be turned into a date. Here's what I wish I could do.

<form action="removeThisData.html" method="post">
  ... blah blah blah ...
  <input type="submit" value="Change blah to date"/>
  <input type="submit" value="Remove"/>
</form>

Unfortunately, that button just acts upon the form action, which invokes the functionality mapped to "removeThisData.html".

How can I get two different behaviors from the same form? Is the invocation of multiple actions even possible within the same form? If it is not, is there a way to preserve all the information within a single scope or do I have to repeat the data/information in two different forms?

Thanks!

A: 

You probably want the change date button to be a <input type="button" onclick="some_javascript();" /> rather than a submit button

Alternatively you could change the action with an onclick along the lines of onclick="this.form.action='changeDate.jsp';"

Another way still is to give name and value attributes to your submit buttons then have a switch in your JSP page logic on the value of this variable (i.e. if you named them all submit, you could see which button was clicked on by testing the value of the submit post argument)

tobyodavies
+1  A: 

You could rename removeThisData.html to, say, "manageThisData.html". You can examine the "value" of the submit button on the server-side and perform suitable action, based on the value, which would be one of "Remove" or "Change blah to date".

Raghuram
Thank you very much! This worked and gave me something to work with on the server end.For future readers: if you keep getting null when you check for the value, try all possible names, too.
Danny