title: Checkbox Data Dynamically Save to Database on Click
body: <p>I need some js/ajax/jquery script saving data to database dynamically when I check the check-box.
  the checkboxes at the moment or loaded in next to records and change the variable in the database depending if its checked or not.but i have to reload the page after i select one to save it to the database. i can do everything else but understand how to implement the ajax to this so i don't have to submit the query and refresh the page every time. any help is greatly appreciated.</p>
  
  <pre><code>    &lt;form name="form1aa" method="post" action="process.php?fn=&lt;? echo $rows['first']; ?&gt;&amp;class=&lt;?php echo $rows['class']; ?&gt;&amp;last=&lt;?php echo $rows['last']; ?&gt;
  &amp;model=&lt;?php echo $rows['model']; ?&gt;&amp;cas=&lt;?php echo $rows['cases']; ?&gt;&amp;upid=&lt;?php echo $id; ?&gt;&amp;group=1" id="form1a" &gt;
  
      &lt;select name="type" onchange=" fill_damage (document.form1aa.type.selectedIndex); "&gt;
      &lt;option value="Hardware"&gt;Hardware&lt;/option&gt;
      &lt;option value="Software"&gt;Software&lt;/option&gt;
      &lt;/select&gt;
      &lt;select name="damage"&gt;
      &lt;/select&gt;
      &lt;input type=text name="comment"  placeholder="Comments Box"&gt;
      &lt;input type=text name="cost"  placeholder="Cost"&gt;
      &lt;input type="submit" value="Save" name="Save"&gt;
      &lt;/form&gt;
  
  &lt;?php
  
  //Job Status
  if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox'];
  if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"])
  $id = "('" . implode( "','", $checkbox ) . "');" ;
  $sql="UPDATE repairs SET status = '".(isset($activate)?'Completed':'In Progress')."' WHERE id=$id" ;
  $result = mysql_query($sql) or die(mysql_error());
  }
  //End Job Status
  
  //Payment Status
  if(isset($_POST['paycheck'])){$paycheck = $_POST['paycheck'];
  if(isset($_POST['paid'])?$paid = $_POST["paid"]:$unpaid = $_POST["unpaid"])
  $id = "('" . implode( "','", $paycheck ) . "');" ;
  $sql="UPDATE repairs SET paid = '".(isset($paid)?'Paid':'Unpaid')."' WHERE id=$id" ;
  $result = mysql_query($sql) or die(mysql_error());
  }
  //End Payment Status
  
  //Return Status
  if(isset($_POST['retcheck'])){$retcheck = $_POST['retcheck'];
  if(isset($_POST['ret'])?$ret = $_POST["ret"]:$unret = $_POST["unret"])
  $id = "('" . implode( "','", $retcheck ) . "');" ;
  $sql="UPDATE repairs SET ret = '".(isset($ret)?'Retuned':'In Office')."' WHERE id=$id" ;
  $result = mysql_query($sql) or die(mysql_error());
  }
  //End Return Status
  $sql="SELECT * FROM $tbl_name";
  if(isset($_POST['all'])){
      $sql="SELECT * FROM $tbl_name";
  }
  if(isset($_POST['tpc'])){
      $sql="select * from $tbl_name WHERE class LIKE '1%'";
  }
  if(isset($_POST['drc'])){
      $sql="select * from $tbl_name WHERE class LIKE 'D%'";
  }
  if(isset($_POST['bsc'])){
      $sql="select * from $tbl_name WHERE class LIKE 'B%'";
  }
  
  $result=mysql_query($sql);
  
  ?&gt;
  &lt;form  name="frmactive" method="post" action=""&gt;
                  &lt;input name="activate" type="submit" id="activate" value="Complete Job" /&gt;
                  &lt;input name="paid" type="submit" id="Payment" value="Payment Status" /&gt;
                  &lt;input name="ret" type="submit" id="ret" value="Returned 2 Student" /&gt;
                  &lt;br /&gt;
  
  &lt;a id="displayText" href="javascript:toggle();"&gt;Show Extra&lt;/a&gt;
  &lt;div id="toggleText" style="display: none"&gt;
  &lt;br /&gt;
                  &lt;input name="unret" type="submit" id="unret" value="In Office" /&gt;
                  &lt;input name="unpaid" type="submit" id="unpaid" value="Not Paid" /&gt;
                  &lt;input name="deactivate" type="submit" id="deactivate" value="In Progress" /&gt;&lt;/div&gt;
  
  &lt;table width="1000" border="0" cellpadding="3" cellspacing="1"&gt;
  &lt;thead&gt;
  &lt;th width="67" align="center"&gt;&lt;strong&gt;Start Date&lt;/strong&gt;&lt;/th&gt;
  &lt;th width="50" align="center"&gt;&lt;strong&gt;Cases&lt;/strong&gt;&lt;/th&gt;
  &lt;th width="34" align="center"&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/th&gt;
  &lt;th width="120" align="center"&gt;&lt;strong&gt;Damage&lt;/strong&gt;&lt;/th&gt;
  &lt;th width="31" align="center"&gt;&lt;strong&gt;Comment&lt;/strong&gt;&lt;/th&gt;
  &lt;th width="31" align="center"&gt;&lt;strong&gt;Cost&lt;/strong&gt;&lt;/th&gt;
  &lt;th width="90" align="center"&gt;&lt;strong&gt;Payment Status&lt;/strong&gt;&lt;/th&gt;
  &lt;th width="100" align="center"&gt;&lt;strong&gt;Returned 2 Student&lt;/strong&gt;&lt;/th&gt;
  &lt;th width="100" align="center"&gt;&lt;strong&gt;Job Status&lt;/strong&gt;&lt;/th&gt;
  &lt;/thead&gt;
  
  &lt;?php
  while($rows=mysql_fetch_array($result)){
  ?&gt;
  &lt;tr&gt;
  
  &lt;td&gt;&lt;? echo $rows['start']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;? echo $rows['cases']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;? echo $rows['type']; ?&gt;&lt;/td&gt;
  &lt;td width="70"&gt;&lt;? echo $rows['damage']; ?&gt;&lt;/td&gt;
  &lt;td width="70"&gt;&lt;? echo $rows['comment']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;? echo "$"; echo $rows['cost']; ?&gt;&lt;/td&gt;
  
  &lt;!--Payment Display(Start)--&gt;
  &lt;?php 
          if($rows['paid']=="Paid")
          {
                  ?&gt;
                      &lt;td&gt;&lt;input name="paycheck[]" type="checkbox" id="paycheck[]" value="&lt;? echo $rows['id']; ?&gt;"&gt;
                  &lt;? echo $rows['paid'];?&gt;
                      &lt;/td&gt;
                      &lt;?
  }
  
          if($rows['paid']=="Unpaid")
          {
                ?&gt;
                      &lt;td width="21"&gt;&lt;input name="paycheck[]" type="checkbox" id="paycheck[]" value="&lt;? echo $rows['id']; ?&gt;"&gt;
                  &lt;? echo $rows['paid']; ?&gt;
                      &lt;/td&gt;
                      &lt;?
  }
  if($rows['ret']==""){
      ?&gt;
      &lt;td width="50"&gt;No Data&lt;/td&gt;
      &lt;?
  }
  ?&gt;
  </code></pre>