0

I am working in a project that have a Person model. I display the Persons in an Index action with a table, showing Checkboxes allowing to select multiple people.

The user is supposed to be able to do different things to the selected people, like:

  1. Approving them for access.
  2. Sending an email message.

The action of approving them for access is just making a database change. The action of "Sending an email" should redirect to another page that would request the details of the email so it can be send.

So far we have a table inside a Form that have the people. That form is posting to one action and I am able to retrieve the selected IDs. So far so good.

My issue is that I would like the form to post to different routes dynamically (if the user clicks on the action to "approve" the user to go to one place, if the user clicks on the actions to "send email" to go to another place).

I haven't been able to find how to dynamically modify the form action to post to a different Url on runtime. Is there any way to do that? (or maybe I am doing all this wrong, and I should, somehow, collect the IDs with jQuery and post to the Urls that I want).

rufo
  • 5,158
  • 2
  • 36
  • 47
  • Seems that this might be the solution: http://stackoverflow.com/questions/1925614/jquery-change-form-action-based-on-selection. I am looking into that and will post back. – rufo Nov 23 '12 at 19:35

1 Answers1

0

What you need to do is to change (on the client, using javascript) "action" attribute of the form element:

var url = ...
$("form").attr("action", url);
Igor
  • 15,833
  • 1
  • 27
  • 32
  • Yes. Thanks. This link has more information: http://stackoverflow.com/questions/1925614/jquery-change-form-action-based-on-selection – rufo Nov 23 '12 at 21:09