title: Keep data checked even on form submit
body: <p>I am getting all the data in the form using Javascript because the checked data can either be updated or deleted.</p>
  
  <pre><code>&lt;table cellpadding="1" cellspacing="1" id="resultTable"&gt;
      &lt;tr&gt;
          &lt;th&gt;Availability&lt;/th&gt;
          &lt;th&gt;Item&lt;/th&gt;
      &lt;/tr&gt;
     &lt;?php
          if(mysqli_num_rows($query) &gt; 0){
          while($row = mysqli_fetch_assoc($query)){
          extract($row);
          ?&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;input type="checkbox" name="selected_id[]" class="checkbox" value="&lt;?php echo $id; ?&gt;" /&gt;&lt;/td&gt;
          &lt;th&gt;&lt;?php echo $item; ?&gt;&lt;/th&gt;
      &lt;/tr&gt;
      &lt;?php } }else{ ?&gt;
          &lt;tr&gt;&lt;td colspan="3"&gt;No records found.&lt;/td&gt;&lt;/tr&gt; 
      &lt;?php } ?&gt;
      &lt;form name="updateForm" method="post" action="updateproduct.php"&gt;
          &lt;select name="availability" id="availability" required onchange="enableButton()"&gt;
             &lt;option disabled="disabled" selected="selected" value=''&gt;Select an option.&lt;/option&gt;
             &lt;option value="Available today"&gt;Available today&lt;/option&gt;
             &lt;option value="Not available today"&gt;Not available today&lt;/option&gt;
          &lt;/select&gt;
       &lt;/form&gt;
       &lt;input type="submit" id="btn_update" value="Update Records" /&gt; 
       &lt;input type="submit" id="btn_delete" value="Delete Records" /&gt;
  &lt;/table&gt;
  
  &lt;form name="deleteForm" method="post" action="deleteselected.php" onsubmit="return deleteAlert();"&gt;&lt;/form&gt;
  </code></pre>
  
  <p>This is the Javascript that I've used.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
                          function enableButton()
                          {
                              var selectelem = document.getElementById('availability');
                              var btnelem = document.getElementById('btn_update');
                              btnelem.disabled = !selectelem.value;
                          }   
                          function setFormValuesAndSubmit(form) {
                              const checked = $("#resultTable input[name='selected_id[]']:checked");
                              if (!checked.length) {
                                  alert("Please select an item.");
                                  return;
                              }
  
                              form = $(form);
                              form.find("[name='selected_id[]']").remove();
                              checked.each(function(){
                                  $("&lt;input/&gt;", {type: "hidden", name: "selected_id[]", value: $(this).val()}).appendTo(form);
                              });
                              form.submit();
                          }
                          $("#btn_update").click(function() {
                              setFormValuesAndSubmit(document.updateForm);
                          });
                          $("#btn_delete").click(function(){
                              setFormValuesAndSubmit(document.deleteForm);
                          });
  &lt;/script&gt;
  </code></pre>
  
  <p>My question is how can I keep the data checked still checked even when the form is submitted? Is there any way that I can use php for this? I am not familiar in JSON</p>