I'm trying to implement a little ajax form using jQuery.
My simplified form looks something like this, I gave all the inputs and textareas the class="form_one_inputs" :
<form action="myform" id="form_one" method="post" >
<div class="formleft">
<p>Name</p>
</div>
<div class="formright">
<input name="name" type="text" class="form_one_inputs" ></div>
</div>
...
<input id="email" maxlength="45" name="email" class="form_one_inputs" type="email">
...
<textarea id="Comments" name="Comments" class="form_one_inputs" >
...
In my jquery function, I can make my ajax submit work if I put all the form data into this object:
var formData = {
'name' : $('input[name=name]').val(),
'email' : $('input[name=email]').val(),
'Comments' : $('textarea[name=Comments]').val(),
'subject' : $('input[name=subject]').val()
};
I can loop through all the inputs and textareas like this :
$('.form_one_inputs').each(function(index, obj){
alert(index + " : " + obj.value + ":" + obj.name);
//
// need to add each input to formData object
});
How can I generalize my code to put all the elements of class="form_one_inputs" into the formData object. I've been trying, but not succeeding with formData.push()
.serializeArray()? api.jquery.com/serializeArray