I have an AJAX call which dynamically generates a HTML form. This form contains a number of elements including inputs, selects, textareas, checkboxes as well as etc.
I need to write some javascript (jquery available) to get all the fields in this form and submit them to an AJAX script. I won’t know how many or what fields are there (only a basic idea) as it all depends on what the user does.
Any ideas how to do this? Lets say my form name is ‘ajaxform’
As everyone said, use jQuery serialize. One other note is to override your form submit (if needed) via jQuery live method:
//Override form submit $("form").live("submit", function (event) { event.preventDefault(); var form = $(this); $.ajax({ url: form.attr('action'), // Get the action URL to send AJAX to type: "POST", data: form.serialize(), // get all form variables success: function(result){ // ... do your AJAX post result } }); });