0

How do I serializeArray() the input and textarea inside the .panel without having a form?

$(document).on("click", ".sec-form-btn", function(e) {
  var element = $(this);
  var formData = element.parents('.panel :input').serializeArray();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="panel panel-warning">
  <div class="panel-heading">
    <span class="h4">Day - 1</span> |
    <span class="secTitle"><input name="sec[title]" value="Day 1" type="text"></span>
    <span class="pull-right panel-menu" data-secid="11">
      <a href="#" class="btn btn-primary btn-sm sec-form-btn">Save changes</a>
      <span class="fa fa-refresh fa-spin fa-1x fa-fw edit-sec-loader hidden"></span>
    </span>
  </div>
  <div class="panel-body">
    <div class="secDes mb10">
      <textarea name="sec[des]" class="form-control"></textarea>
    </div>
  </div>
</div>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Roi
  • 153
  • 1
  • 11
  • You can't. `serializeArray()` can only be called on a `form`. If you don't want to use a `form` element you'll need to write the logic to create the array/objects yourself – Rory McCrossan Jun 21 '18 at 15:08
  • Hi @RoryMcCrossan. what about this - https://stackoverflow.com/questions/9589126/jquery-serialize-serializearray-from-an-element-that-is-not-a-form ? I see that there is a solution.... – Roi Jun 21 '18 at 15:11
  • Well, that uses `serialize()` which returns a querystring not an array, and the answers suggesting `$('div :input').serializeArray()` are now incorrect as it doesn't work - as you can see from this: http://jsfiddle.net/9uyz5/149/ – Rory McCrossan Jun 21 '18 at 15:18

0 Answers0