VAAA VAAA - 6 months ago 19
jQuery Question

jQuery div serialize restul is empty string

Hi I have a div (form) that I want to serialize using jQuery but the result is an empty string.

Here is my html code:

<div id="rakebackForm" class="wrapper wrapper-white">
<div class="page-subtitle">
<h3>RakeBack New Record</h3>
<p>Please enter all the information requested.</p>
</div>


<div class="row">
<div class="col-md-6">
<div class="form-group">
<label><span>Start Date</span></label>
<input name="StrStartDate" type="text" class="form-control datepicker">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label><span>End Date</span></label>
<input name="StrEndDate" type="text" class="form-control datepicker">
</div>
</div>
</div>

<div class="row">
<div class="col-md-6">
<div class="form-group">
<label> <span>Amount</span></label>
<input name="Amount" type="text" class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label> <span>Site</span></label>
<input name="Site" type="text" class="form-control">
</div>
</div>
</div>



</div>


and this is my jQuery code:

var form = $('#rakebackForm');
var data = form.serialize();



Any clue on what I'm doing wrong?

Answer

You need to use serialize() with form or form elements, and use jQuery :input pseudo selector to get form elements

var form = $('#rakebackForm :input');
var data = form.serialize();
Comments