laluk
laluk

Reputation: 37

Two submits actions in a single button

I would like to make as my title says, I want to send form´s info to two different pages.

My intention is:

If someone choose one option in the form I want to send the information to page1, but if they select other option I want to send that info to another page. Using only a single button.

Is that possible?

I found info about submit the form two different page but using two button and I want do it only in a single button.

I appreciate any help.

Upvotes: 0

Views: 109

Answers (2)

h2ooooooo
h2ooooooo

Reputation: 39532

Sure, just use prop() and change the "action" property of the form:

<script type="text/javascript">
    $(document).ready(function() {
        $('#post-to-bar').change(function() {
            var action = 'foo.php';
            if ($(this).is(':checked')) {
                action = 'bar.php';
            }

            $('#my-form').prop('action', action);
        });
    });
</script>

<form action="foo.php" method="post" id="my-form">
    <input type="checkbox" id="post-to-bar" />
    <input type="submit" value="Submit!" />
</form>

Upvotes: 1

LoicAG
LoicAG

Reputation: 633

You can achieve this behaviour by changing the form's action, cf this question: javascript - change form action based on selection?

Upvotes: 1

Related Questions