Results 1 to 3 of 3

Thread: [RESOLVED] Post form to different action results (jQuery, not Ajax)

  1. #1

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Resolved [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>


  2. #2
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Post form to different action results (jQuery, not Ajax)

    Have you tried,

    Code:
    $("#xxxListForm").attr("action","NewAction");
    
    //Now Submit

  3. #3

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    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
  •  



Click Here to Expand Forum to Full Width