multiple submit buttons
Hi
I have a form in which I have 2 buttons
save and new - saves form and returns back to this page
save and close - saves form and returns to the main menu
This means here I have 2 buttons .. one action .. and 2 forwards .
How do I implement this any idea ?
Thanks
[309 byte] By [
ns123a] at [2007-10-2 16:48:37]

Hi .. I have a page with 2 submit buttons .
I have one "save" action
Save & New button-> goes to the save action and on success it comes back to the same form
Save & Close button -> goes to the save action and on success it goes to the mainmenu .
So I need some way in which my action class can check which button was pressed and appropriately forward to the same page or main menu page
ns123a at 2007-7-13 17:59:45 >

Have a hidden field whose name is say buttonPressed.
Have a javascript function that submits your form.
Call this function on the click of the 2 buttons.
Pass the form object and an identifier for the button along when this function is called.
<script>
function doSubmit (f, whichButton){
f.buttonPressed.value = whichButton;
f.submit();
return false;
}
</script>
<form action = "url">
<input type = "hidden" name = "buttonPressed">
//other fields
<input type = "submit" value = "Save And New" onClick = "doSubmit(this.form, 'new')>
<input type = "submit" value = "Save And Close" onClick = "doSubmit(this.form, 'close')>
</form>
The value of request.getParameter("buttonPressed") on the server will tell you which button was clicked.
ram.>
A slight modification.
<input type = "submit" value = "Save And New" onClick = "return doSubmit(this.form, 'new')">
<input type = "submit" value = "Save And Close" onClick = "return doSubmit(this.form, 'close')">
ram.