serializeArray doesn't include submit-button value

Posted by guzh on Stack Overflow See other posts from Stack Overflow or by guzh
Published on 2011-01-05T22:43:17Z Indexed on 2011/01/05 22:54 UTC
Read the original article Hit count: 100

Filed under:
|
|

Hi, I got two submit buttons in a form. One that deletes the post, and one to edit it.

I want to display a fancybox with either the edit-form or a message saying that the user deleted the post. It's all decided by which button was pushed, with a "if(isset)"-sentence in edit.php. However I can't figure out how to get the value of the button within the serializeArray.. I tried with .click(function() instead, but that didn't send anything to the fancybox..

$("#form").bind("submit", function() {
                    $.ajax({
                        type        : "POST",
                        cache       : false,
                        url         : "edit.php",
                        data        : $(this).serializeArray(),
                        success: function(data) {
                            $.fancybox(data);
                        }
                    });

                    return false;
                });

The form looks like this:

<form method='post' action='' id="form">
    <input type='submit' value='Edit' name='edit' />
    <input type='submit' value='Delete' name='delete' onClick="return slett('<?php echo $oppgave->name; ?>')"/>
    <input name='oppgaveID' type='hidden' value='<?php echo $oppgave->id; ?>' />
</form>

I would really appreciate it if someone could help me! Thanks in advance!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery