-
May 18th, 2010, 07:34 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Post form to different action results (jQuery, not Ajax)
I got a form that I submit when a dropdown value change using jQuery.
Thing is, I want to submit the form to different action methods depending on which dropdown option was selected.
Note that I do not need/want to use Ajax, just post the form to a specific action method.
Currently I'm trying something like this (don't work. It just submit the form to the initial action method (Index)
Code:
<script type="text/javascript">
$("select#xxxAction").change(function () {
var action = $("#xxxAction > option:selected").attr("value");
if (action) {
// TODO: Want to submit the form and have the actionmethod able to determine
// the selected items, as well as the action to perform
var form = $("#xxxListForm");
if (action == "Deletexxxs") {
form.action = "/Deletexxxs/"; //action method name
form.submit();
} else if (action == "Archivexxxs") {
form.action = "/Archivexxxs/"; //action method name
form.submit();
}
}
});
</script>
-
May 18th, 2010, 09:17 AM
#2
Re: Post form to different action results (jQuery, not Ajax)
Have you tried,
Code:
$("#xxxListForm").attr("action","NewAction");
//Now Submit
-
May 18th, 2010, 11:10 AM
#3
Thread Starter
Hyperactive Member
Re: Post form to different action results (jQuery, not Ajax)
Thanks. Tried that and there was an improvement in the sense it *tried* to do what I ask but gave me some error about a post not being allowed.
Figured that's what you get when you break your own "all views should be strongly typed" rule, and went ahead creating a simple view model containing a list of items, a list of actions (for the dropdown) and a member indicating the action.
Simply had the jquery do a normal post, and in the action method receiving my model I check if items where checked and if a action was selected and act accordingly.
Bit messy, but will refactor it into something clean.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|