Monday, October 06, 2008

Submit a Form with Multiple Buttons in Monorail

Here's how to submit a form with multiple buttons via MonoRail. The javascript will control which action is called in the controller. This example uses prototype to setup the event handlers:

<button id="addbutton">Add</button>
<button id="removebutton">Remove</button>


Event.observe(window, 'load', function() {

Event.observe('addbutton', 'click', function() {
$('myform').action = '$Url.For("%{action='addemail'}")';
return false;

Event.observe('removebutton', 'click', function() {
$('myform').action = '$Url.For("%{action='removeemail'}")';
return false;


I used to format the code.

No comments: