开发者

jQuery submit form on link click

I have a big form that is split over 3 pages (each page is self contained i.e. only contain part of the form wrapped around form tags). I have page buttons so the user can navigate between pages e.g. page 1, page 2, page 3 and each page is loaded depending on a page variable in the url querystring i.e.

www.myurl.com?page=1

What I want to happen is that when the user clicks on the page button the form is submitted but also passed t开发者_如何学Pythonhe page button clicked in a post/get (I don't mind which) value i.e. next_page = page number clicked

What is the best way to do this? I am using jQuery in my code so a solution using this would be good


$(document).ready(function() {
    $('.page_button').click(function() {
        var url = window.location.href;
        var button = $(this);
        $postData = $('#my_form').serialize() + '&save=Save';
        $.post(url, $postData, function(data) {
            window.location.href = button.attr('href');
        });

        return false;
    });
});


use tab based form

read this article

personally prefer


With this $(window.location).attr('search') you can find page=1 Put this value in a hidden like this

var hidden_value = $(window.location).attr('search');
$('form').append('<input type="hidden" value="'+hidden_value+'" name="page_number" />');

And finaly submit your form with form.submit();


Am I right that you do not only need to pass the page number to the next page but also regular data from a form? Why not have a hidden input which you set to next_page_number before the form is submitted?

This would be part of POST-Data on your next page then.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜