March 7, 2012

jquery .serialize()

Question by Cjueden

I can’t get jquery .serialize() to work correctly. I have a form of dynamically generated checkboxes. The page wont submit the check boxes. Can you please tell me where I went wrong.

            var current_class = $('#class_choice :selected').attr('name');// GET CURRENT CLASS
            var prof_id = $('#prof_id').text();// GET PROFFESSOR ID NUMBER
                var query_string = $(this).serialize(); 

                $("#take_attendance_prof")// CALL TO FORM  
                .load(loadUrl, "form_being_submitted=prof_save_attendance&class="+current_class+"&prof_id="+prof_id+""+query_string);


Answer by charlietfl

Based on assumption that $('#prof_take_attendance_submit') is a submit button you are trying to serialize just the button


   var query_string = $(this).closest('form').serialize(); 

Without more info about form is pretty hard to see what elese may not be working

EDIT: Get rid of trigger, bind submit to form not button

 $("#prof_take_attendance_form").live('submit', function(){
      var query_string = $(this).serialize(); 

       /* other code and ajax*/


Answer by Starx

Serialize the form not the button


Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!