Expl0de
Expl0de

Reputation: 687

I can't serialize form from the object

I use scroll-pagination as a plugin in my page, And I use form to pass value to url i'm fetching the result.

After loaded new form will dynamically add to my page,and I want to serialize the new form to repete the progress with new page problem is, My code keep serialize the first form not the new one.

This is my Jquery

$(function(){
var datastring=$(".passform").last().serialize();
$('#update').scrollPagination({
    'contentPage': 'post_update.php', 
    'contentData': {
        data : datastring
        },
    'scrollTarget': $(window), 
    'heightOffset': 10, 
    'beforeLoad': function(){ 
        $('#loading').fadeIn(); 
    },
    'afterLoad': function(elementsLoaded){ 
         $('#loading').fadeOut();
         var i = 0;
         $(elementsLoaded).fadeInWithDelay();
                 datastring=$(".passform",elementsLoaded).serialize();  //Here's the Problem:S
    }
});

$.fn.fadeInWithDelay = function(){
    var delay = 0;
    return this.each(function(){
        $(this).delay(delay).animate({opacity:1}, 200);
        delay += 100;
    });};});

This is my first form in main code

<form id="passform" class="passform" name="passform">
        <input name="totalpage" type="hidden" value="<? echo($totalpage);?>" />
        <input name="nowpage" type="hidden" value="0" />
        <input name="u_id" type="hidden" value="<? echo($u_id);?>" />
        </form>

This is the new form that Dynamically add

 <form class="passform" id="passform" name="passform">
        <input name="totalpage" type="hidden" value="<? echo($totalpage);?>" />
        <input name="nowpage" type="hidden" value="<? echo($nowpage);?>" />
        <input name="u_id" type="hidden" value="<? echo($u_id);?>" />
        </form>

Upvotes: 0

Views: 348

Answers (1)

Jai
Jai

Reputation: 74748

change first datastring:

var datastring=$(".passform").first().serialize();

and this datastring in afterload:

datastring=$(document).find(".passform").last().serialize();

note:

Using same id for multiple elems is not valid. When this happens then only first of its type will get selected.

Upvotes: 2

Related Questions