checkbox

by anthony salamin

HTML

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<!--a checkbox outside the form tag-->
<input type="checkbox" id="1" class="outsider" />
<input type="checkbox" id="2" class="outsider" />


<!--begening of the form-->
<div>

  <form id="reservation" name="email-form" data-name="Email Form" method="post">
    <input type="text" id="inside" />
    <input type="text" name="email" />
    <input type="submit" value="submit" />
  </form>

</div>

JavaScript

$("#reservation").submit(function(evt) {

  // append input control at start of form
 $('.outsider:checked')
     .attr("id", "myfieldid")
     .attr("name", "myfieldid")
     .prependTo("#reservation");
  evt.preventDefault();
});