Reverse or hide jQuery ajax for input checkbox results - php

I don't have good knowledge about jquery, so I have a code working good but their problem, is to hide the result when uncheck the checkbox .( check to get the results from the database - uncheck hide these results )
catfd.php code
<input type="checkbox" value="2" class="catcf"> catfd2 <br />
<input type="checkbox" value="35" class="catcf"> catfd35 <br />
<input type="checkbox" value="22" class="catcf"> catfd22 <br />
<input type="checkbox" value="133" class="catcf"> catfd133 <br />
<input type="checkbox" value="28" class="catcf"> catfd28 <br />
<input type="checkbox" value="33" class="catcf"> catfd33 <br />
<input type="checkbox" value="55" class="catcf"> catfd55 <br />
<input type="checkbox" value="44" class="catcf"> catfd44 <br />
<div class="main-area-courses-continer">
<!-- here will echo the results -->
</div>
jquery ajax code get the result from PHP page 'getvalue.php'
if(isset($_POST['catcf'])){
?>
<div class="main-area-courses-continer" >
<?php
$catcfid= $_POST['catcf'];
$sql = 'SELECT * FROM tablename where cat_id = '.$catcfid.' order by p_id asc';
$catandproid = $wpdb->get_results($sql);
foreach($catandproid as $key){
/////////////////////////////////Updates
?>
<div class="<?php echo $catcfid; ?>" >
<?php
echo $key->title;
?>
</div><!-- End of Continer catcfid -->
<?php
////////////////////////////////////////////
}
}
?>
</div>
and the is the ajax jquery code
$(document).ready(function() {
$(".catcf").on('click', function() {
if ($('input.catcf').is(':checked')) {
var catcf = Number($(this).val());
$.ajax({
url: 'getvalue.php',
type: 'post',
data: {
catcf: catcf
},
beforeSend: function() {
$(".main-area-courses-continer").html("Looding....");
},
success: function(response) {
// Setting little delay while displaying new content
setTimeout(function() {
// appending posts after last post with class="post"
$(".main-area-courses-continer:last").after(response).show().fadeIn("slow");
$(".main-area-courses-continer").html("");
}, 2000);
}
});
}
});
});

You can check if the div with class="catcfid" exist in your DOM or not using $(".main-area-courses-continer > ." + catcf).length == 0 if the length is 0 means there is no such div then you can make ajax request to bring that from backend else just show that div using $("." + catcf).parent().show(); else if unchecked hide that div using $("." + catcf).parent().show(); .
Demo Code :
$(document).ready(function() {
$(".catcf").on('click', function() {
var catcf = Number($(this).val());
if ($(this).is(':checked')) {
//check if the div with class catcf is not there
if ($(".main-area-courses-continer > ." + catcf).length == 0) {
/*.ajax({
url: 'getvalue.php',
type: 'post',
data: {
catcf: catcf
},
beforeSend: function() {
$(".main-area").html("Looding....");
},
success: function(response) {*/
setTimeout(function() {
//$(".main_container:last").after(response).show().fadeIn("slow");
//dummy data append ..
$(".main_container:last").after('<div class="main-area-ourses-continer"><div class="' + catcf + '">catfd' + catcf + ' data....</div> </div>')
$(".main-area").html("")//empty loading ..
}, 100);
/*
});*/
} else {
//show that class
$("." + catcf).parent().show();
}
} else {
//hide that class means unchecked
$("." + catcf).parent().hide()
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" value="2" class="catcf" checked> catfd2 <br />
<input type="checkbox" value="35" class="catcf"> catfd35 <br />
<input type="checkbox" value="22" class="catcf" checked> catfd22 <br />
<input type="checkbox" value="133" class="catcf"> catfd133 <br />
<input type="checkbox" value="28" class="catcf"> catfd28 <br />
<input type="checkbox" value="33" class="catcf"> catfd33 <br />
<input type="checkbox" value="55" class="catcf" checked> catfd55 <br />
<input type="checkbox" value="44" class="catcf"> catfd44 <br /> Datas :
<!--put this div for loading separtely-->
<div class="main-area"></div>
<div class="main_container">
<div class="main-area-courses-continer">
<div class="2">
catfd2 data....
</div>
</div>
<div class="main-area-courses-continer">
<div class="22">
catfd22 data....
</div>
</div>
<div class="main-area-courses-continer">
<div class="55">
catfd55 data....
</div>
</div>
</div>

Just change the QUERY, and I think that's the issue
$sql = 'SELECT * FROM tablename Where cat_id = '.$catcfid.' And status = '1' order by p_id ASC';

Related

How to connect Jquery draggable UI with mysql via AJAX

I would like to drag elements in my horizontal list and than save the position in mysql.
The text sort=1&sort=2.... ist just for testing purpose.
this is my code in jquery
$("#sortable").sortable({
stop: function(event, ui) {
var data = $(this).sortable('serialize', {key:"sort"});
$('#tags').text(data);
$.ajax({
data: data,
type: 'POST',
url: 'listpriority.php'
});
}
});
The sortable function is working. It serializes me the list.
Now on the server side i would like to recive the serialized data.
my php code:
<?php
print_r($_POST['sort']);
?>
But the print_r function show me only the length of the list.
the full php code should be:
<?php
include = ""; // the connection to sql
if(isset($_POST['sort'])) {
$sort = $_POST['sort'];
$sql = "UPDATE tags SET position='".$sort."'";
$result = mysqli_query($conn, $sql);
}
?>
My solution for the problem:
$( "#sortable" ).sortable({
update: function(event, ui) {
var data = $(this).sortable('serialize', { key: "sort" });
$('#tags').text(data);
$.post("listpriority.php", {data});
}
});
i changed the $.ajax to $.post and than i echo out the data in php echo($_POST['data']);
Try to get and set data from hidden field
<div class="main_div">
<div class="inner">
<span>1</span>
<input type="hidden" name="original[]" value="1">
<input type="hidden" name="new[]" class="new_ord" value="1">
</div>
<div class="inner">
<span>2</span>
<input type="hidden" name="original[]" value="2">
<input type="hidden" name="new[]" class="new_ord" value="2">
</div>
<div class="inner">
<span>3</span>
<input type="hidden" name="original[]" value="3">
<input type="hidden" name="new[]" class="new_ord" value="3">
</div>
<div class="inner">
<span>4</span>
<input type="hidden" name="original[]" value="4">
<input type="hidden" name="new[]" class="new_ord" value="4">
</div>
<div class="inner">
<span>5</span>
<input type="hidden" name="original[]" value="5">
<input type="hidden" name="new[]" class="new_ord" value="5">
</div>
</div>
And php script is
if(isset($_POST['post']) == 1) {
$original = $_POST['original'];
$new_val = $_POST['new_val'];
for ($i=0; $i < count($original); $i++) {
$sql = 'UPDATE TABLE Table_name SET order="'.$new_val[$i].'" WHERE id="'.$original[$i].'"';
echo $sql."\n\r";
}
}
See jquery code here and uncomment ajax call portion
Maybe it helps you

Generate multiple barcode at once

I'm currently developing warehouse inventory system. And the only task left is how to generate and print the bin IDs of the rack. The code below generate only 1 barcode. It only generates the last checked item. I need to print multiple barcode at once for printing. Here's the link I used as a reference to generate the barcode.
<?php
require ("../../connect/db.php");
$sql = "select * from location_bin where rack_id = 3";
$rack = mysqli_query($mysqli, $sql);
while($row = mysqli_fetch_array($rack)){
$id = $row['bin_id'];
echo "<input type='checkbox' name='barcodeValue' id='barcodeValue' value='$id'/>$id<br>";
}
?>
Here's the script in generating the barcode.
<script type="text/javascript">
function generate(){
$(document).ready( function() {
$("input[name=barcodeValue]:checked").each(function () {
var id = $(this).attr("value");
function generateBarcode(id){
var value = id;
var btype = $("input[name=btype]:checked").val();
var renderer = $("input[name=renderer]:checked").val();
var quietZone = false;
if ($("#quietzone").is(':checked') || $("#quietzone").attr('checked')){
quietZone = true;
}
var settings = {
output:renderer,
bgColor: $("#bgColor").val(),
color: $("#color").val(),
barWidth: $("#barWidth").val(),
barHeight: $("#barHeight").val(),
moduleSize: $("#moduleSize").val(),
posX: $("#posX").val(),
posY: $("#posY").val(),
addQuietZone: $("#quietZoneSize").val()
};
if ($("#rectangular").is(':checked') || $("#rectangular").attr('checked')){
value = {code:value, rect: true};
}
if (renderer == 'canvas'){
clearCanvas();
$("#barcodeTarget").hide();
$("#canvasTarget").show().barcode(value, btype, settings);
} else {
$("#canvasTarget").hide();
$("#barcodeTarget").html("").show().barcode(value, btype, settings);
}
}
function showConfig1D(){
$('.config .barcode1D').show();
$('.config .barcode2D').hide();
}
function showConfig2D(){
$('.config .barcode1D').hide();
$('.config .barcode2D').show();
}
function clearCanvas(){
var canvas = $('#canvasTarget').get(0);
var ctx = canvas.getContext('2d');
ctx.lineWidth = 1;
ctx.lineCap = 'butt';
ctx.fillStyle = '#FFFFFF';
ctx.strokeStyle = '#000000';
ctx.clearRect (0, 0, canvas.width, canvas.height);
ctx.strokeRect (0, 0, canvas.width, canvas.height);
}
$(function(){
$('input[name=btype]').click(function(){
if ($(this).attr('id') == 'datamatrix') showConfig2D(); else showConfig1D();
});
$('input[name=renderer]').click(function(){
if ($(this).attr('id') == 'canvas') $('#miscCanvas').show(); else $('#miscCanvas').hide();
});
generateBarcode(id);
});
});
});
}
</script>
Below is the HTML code.
<div class="title">Type</div>
<input type="radio" name="btype" id="code39" value="code39" checked><label for="code39">code 39</label><br />
<input type="radio" name="btype" id="code93" value="code93"><label for="code93">code 93</label><br />
<input type="radio" name="btype" id="code128" value="code128"><label for="code128">code 128</label><br />
<input type="radio" name="btype" id="datamatrix" value="datamatrix"><label for="datamatrix">Data Matrix</label><br /><br />
</div>
<div class="config" style="display:none">
<div class="title">Misc</div>
Background : <input type="text" id="bgColor" value="#FFFFFF" size="7"><br />
"1" Bars : <input type="text" id="color" value="#000000" size="7"><br />
<div class="barcode1D">
bar width: <input type="text" id="barWidth" value="1" size="3"><br />
bar height: <input type="text" id="barHeight" value="50" size="3"><br />
</div>
<div class="barcode2D">
Module Size: <input type="text" id="moduleSize" value="5" size="3"><br />
Quiet Zone Modules: <input type="text" id="quietZoneSize" value="1" size="3"><br />
Form: <input type="checkbox" name="rectangular" id="rectangular"><label for="rectangular">Rectangular</label><br />
</div>
<div id="miscCanvas">
x : <input type="text" id="posX" value="10" size="3"><br />
y : <input type="text" id="posY" value="20" size="3"><br />
</div>
</div>
<div class="config">
<div class="title">Format</div>
<input type="radio" id="css" name="renderer" value="css" checked="checked"><label for="css">CSS</label><br />
<input type="radio" id="bmp" name="renderer" value="bmp"><label for="bmp">BMP (not usable in IE)</label><br />
<input type="radio" id="canvas" name="renderer" value="canvas"><label for="canvas">Canvas (not usable in IE)</label><br />
</div>
</div>
<div id="submit">
<input type="button" onClick="generate();" value=" Generate the barcode ">
</div>
</div>
<div id="barcodeTarget" class="barcodeTarget"></div>
<canvas id="canvasTarget" width="150" height="100"></canvas>
Output screenshot
Try this, also made a JSFIDDLE
HTML
<input class="thischeckbox" type='checkbox' name='123' id='123' value='123' />123
<br>
<input class="thischeckbox" type='checkbox' name='456' id='456' value='456' />456
<br>
<input class="thischeckbox" type='checkbox' name='789' id='789' value='789' />789
<br>
<div class="title">Type</div>
<input type="radio" name="btype" id="code39" value="code39" checked>
<label for="code39">code 39</label>
<br />
<input type="radio" name="btype" id="code93" value="code93">
<label for="code93">code 93</label>
<br />
<input type="radio" name="btype" id="code128" value="code128">
<label for="code128">code 128</label>
<br />
<input type="radio" name="btype" id="datamatrix" value="datamatrix">
<label for="datamatrix">Data Matrix</label>
<br />
<br />
<div class="config">
<div class="title">Format</div>
<input type="radio" id="css" name="renderer" value="css" checked="checked">
<label for="css">CSS</label>
<br />
<input type="radio" id="bmp" name="renderer" value="bmp">
<label for="bmp">BMP (not usable in IE)</label>
<br />
<input type="radio" id="canvas" name="renderer" value="canvas">
<label for="canvas">Canvas (not usable in IE)</label>
<br />
</div>
<div class="config">
<div class="title">Misc</div>
Background :
<input type="text" id="bgColor" value="#FFFFFF" size="7">
<br /> "1" Bars :
<input type="text" id="color" value="#000000" size="7">
<br />
<div class="barcode1D">
bar width:
<input type="text" id="barWidth" value="1" size="3">
<br /> bar height:
<input type="text" id="barHeight" value="50" size="3">
<br />
</div>
<div class="barcode2D">
Module Size:
<input type="text" id="moduleSize" value="5" size="3">
<br /> Quiet Zone Modules:
<input type="text" id="quietZoneSize" value="1" size="3">
<br /> Form:
<input type="checkbox" name="rectangular" id="rectangular">
<label for="rectangular">Rectangular</label>
<br />
</div>
<div id="miscCanvas">
x :
<input type="text" id="posX" value="10" size="3">
<br /> y :
<input type="text" id="posY" value="20" size="3">
<br />
</div>
</div>
<div id="submit">
<input id="generatecode" type="button" onClick="generate();" value=" Generate the barcode ">
</div>
<div id="barcodeTarget" class="barcodeTarget"></div>
<canvas id="canvasTarget" width="150" height="100"></canvas>
js
$('.barcode2D').hide();
$('.barcode1D').show();
$('#miscCanvas').hide();
$('#generatecode').click(function() {
$('input[type=checkbox]:checked').each(function() {
var id = $(this).attr("id");
generateBarcode(id)
});
});
$(document).on('change', 'input[name=btype]', function() {
if ($(this).attr('id') == 'datamatrix') {
showConfig2D();
} else {
showConfig1D();
}
});
$(document).on('change', 'input[name=renderer]', function() {
if ($(this).attr('id') == 'canvas') {
$('.config').show();
$('#miscCanvas').show();
} else {
$('.config').show();
$('#miscCanvas').hide();
}
});
function generateBarcode(id) {
var value = id;
var btype = $("input[name=btype]:checked").val();
var renderer = $("input[name=renderer]:checked").val();
var quietZone = false;
if ($("#quietzone").val() != '') {
quietZone = true;
}
var settings = {
output: renderer,
bgColor: $("#bgColor").val(),
color: $("#color").val(),
barWidth: $("#barWidth").val(),
barHeight: $("#barHeight").val(),
moduleSize: $("#moduleSize").val(),
posX: $("#posX").val(),
posY: $("#posY").val(),
addQuietZone: $("#quietZoneSize").val()
};
if ($("#rectangular").is(':checked') || $("#rectangular").attr('checked')) {
alert("Test")
value = {
code: value,
rect: true
};
}
if (renderer == 'canvas') {
clearCanvas();
$("#barcodeTarget").hide();
$("#canvasTarget").show().barcode(value, btype, settings);
} else {
$("#canvasTarget").hide();
$("#barcodeTarget").html("").show().barcode(value, btype, settings);
}
}
function showConfig1D() {
$('.config').show();
$('.barcode2D').hide();
$('.barcode1D').show();
}
function showConfig2D() {
$('.config').show();
$('.barcode1D').hide();
$('.barcode2D').show();
}
function clearCanvas() {
var canvas = $('#canvasTarget').get(0);
var ctx = canvas.getContext('2d');
ctx.lineWidth = 1;
ctx.lineCap = 'butt';
ctx.fillStyle = '#FFFFFF';
ctx.strokeStyle = '#000000';
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.strokeRect(0, 0, canvas.width, canvas.height);
}

How to pass radio button value to php page using angularjs

I am showing radio button in html
<body ng-app="myApp" ng-controller="MainCtrl">
<form enctype="multipart/form-data" id="FileUploadForm" name="FileUpload" ng-submit="submitData(FileUpload)" novalidate>
<div style="text-align: left;font-size: 20px;padding: 10px;color: #487eaa;">
<font> Upload Resume</font>
</div>
<div class="file-upload">
<input type="text" id="name" name="name" ng-model="name" />
<br /><br />
<input type="text" id="place" name="place" ng-model="place" />
<br /><br />
<label class="control-label" for="Dilation" style="padding:3px 0;">Dilation</label>
<label>Yes <input type="radio" name="dilation" id="dilation" ng-model="dilation" value="Yes" ng-checked="false" /></label>
<label>No <input type="radio" name="dilation" id="dilation" ng-model="dilation" value="No" ng-checked="false" /></label>
<br /><br />
<label class="control-label" for="NCT" style="padding:3px 0;">NCT</label>
<label>Right <input type="radio" name="nct" id="nct" ng-model="nct" value="Right" ng-checked="false" /></label>
<label>Left <input type="radio" name="nct" id="nct" ng-model="nct" value="Left" ng-checked="false" /></label>
<br /><br />
<input type="file" id="i_file" name="file" ng-file-select="onFileSelect($files)" multiple />
<br /><br />
<input type="submit" id="submit" name="submit" value="submit" ng-disabled="FileUploadForm.$invalid" />
<br /><br />
<div ng-bind="dilation" ng-hide="dilation"></div>
<div ng-bind="nct" ng-hide="nct"></div>
</div>
</form>
</body>
And here is my angular controller
angular.module('myApp', ['angularFileUpload'])
.controller('MainCtrl', function($scope, $http, $upload) {
$scope.onFileSelect = function($files) {
$scope.message = "";
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
console.log(file);
$scope.upload = $upload.upload({
url: 'upload.php',
method: 'POST',
data: {name: $scope.name,place: $scope.place, dilation: dilation, nct: nct },
file: file
}).success(function(data, status, headers, config) {
$scope.message = data;
}).error(function(data, status) {
$scope.message = data;
});
}
};
});
And here is my php code(upload.php)
$result = array("filename" => $_FILES["file"],"name" => $_POST['name'],"place" => $_POST['place'],"dilation" => $_POST['dilation'],"nct" => $_POST['nct']);
echo json_encode($result);
Here is a fiddle : http://jsfiddle.net/aabyv4kx/
and getting response like this
name:qqq,place:eeee,dilation:{\"ng339\":8},nct:{\"ng339\":10}
I am new to angularjs please help me sort this.

Multiple radio buttons ajax post

I'm new in web programming and I really need your help. I have a form with several radio buttons and I want to insert them into mysql through an ajax post. I can do it for a single button but for more than one I don't have idea how to do it.
This is a part of my html and jquery:
<html>
<script>
$(document).ready(function () {
$("#submit").click(function () {
var q1 = $('input[type="radio"]:checked').val();
if ($('input[type="radio"]:checked').length == "0") {
alert("Select any value");
} else {
$.ajax({
type: "POST",
url: "ajax-check.php",
data: "q1=" + q1,
success: function () {
$("#msg").addClass('bg');
$("#msg").html("value Entered");
}
});
}
return false;
});
});
</script>
</head>
<body>
<div id="msg"></div>
<form method="post" action="">
<div class="Clear">
question1:bla bla bla
<input class="star required" type="radio" name="q1" value="1" />
<input class="star" type="radio" name="q1" value="2" />
<input class="star" type="radio" name="q1" value="3" />
<input class="star" type="radio" name="q1" value="4" />
<input class="star" type="radio" name="q1" value="5" />
</div>
<br />
<div class="Clear">
question2:bla bla bla
<input class="star required" type="radio" name="q2" value="1" />
<input class="star" type="radio" name="q2" value="2" />
<input class="star" type="radio" name="q2" value="3" />
<input class="star" type="radio" name="q2" value="4" />
<input class="star" type="radio" name="q2" value="5" />
</div>
<input type="submit" name="submit" id="submit" />
</form>
</body>
</html>
And here is how I insert the button in mysql:
<?php
$query = mysql_connect("localhost", "root", "");
mysql_select_db('db', $query);
if (isset($_POST['q1'])) {
$choice1 = $_POST['q1'];
$choice2 = $_POST['q2'];
mysql_query("INSERT INTO tb VALUES('','$choice1')");
}
?>
I've tried to make a var for each button but dosen't worked.
How could I post all values in php and what should I change into my ajax and php?
Thanks!
This is how I did the .php
<?php
$query=mysql_connect("localhost","root","");
mysql_select_db('cosmote',$query);
$q = array();
for ($i = 1; $i <= 2; $i++) {
$q[$i] = isset($_POST['q'+$i]) ? mysql_real_escape_string($_POST['q'+$i]) : 0;
}
mysql_query("INSERT INTO tabel (q1,q2) VALUES ('$q[1]','$q[2]')");
?>
OK, here is how to do it. First, add an id to the form:
<form id="myform" method="post" action="">
This will make it easier to access via jQuery. Then, pass the serialized form as the POST data to your PHP script:
$(document).ready(function () {
$("#submit").click(function () {
if ($('input[type="radio"]:checked').length == "0") {
alert("Select any value");
} else {
$.ajax({
type: "POST",
url: "ajax-check.php",
data: $("#myform").serialize(),
success: function () {
$("#msg").addClass('bg');
$("#msg").html("value Entered");
}
});
}
return false;
});
});
After that, you can get the radio button values from the $_POST array in your PHP script:
$_POST['q1'] // value of q1, can be 1-5
$_POST['q2'] // value of q1, can be 1-5
EDIT: The problem with your PHP code is that you used + instead of . for concatenating strings. Write this instead:
$q[$i] = isset($_POST['q'.$i]) ? mysql_real_escape_string($_POST['q'.$i]) : 0;
After this, I'm pretty sure it will work.
You could use .serialize() on the form, it will give you the values of the form as if you was submitting it regularly data: $('form').serialize(),

How can I use the same checkboxes to submit multiple times to create multiple sets of selections?

I want to have a set of checkboxes that use AJAX to post to a PHP page, but after the post I want to be able to use the same checkboxes to send another set of selections to the same PHP page, up to a specified number of sets, and then use the sets as data in the PHP page.
I can't figure out how this would be implemented. Any ideas?
index.php:
<form id="checkboxes">
<input type="checkbox" id="1" name="checkboxes[]" value="1" />
<input type="checkbox" id="2" name="checkboxes[]" value="2" />
<input type="checkbox" id="3" name="checkboxes[]" value="3" />
<input type="checkbox" id="1" name="checkboxes[]" value="4" />
<input type="checkbox" id="1" name="checkboxes[]" value="5" />
<input type="button" id="button" name="submit" value="Submit" />
</form>
<script type="text/javascript">
$(function() {
$("#button").click(function() {
$.ajax({
type: "POST",
url: "process.php",
data: $("form#checkboxes").serialize(),
success: function(data) {
$("#div").load('success.php')
}
});
})
})
</script>
process.php:
$data = array();
foreach($_POST['checkboxes'] as $key => $value){
$data[] = "$value";
}
You need to use Sessions, if you want data to prevail over time. So, you can use it this way:
<?php
session_start();
if (!isset($_SESSION["data"]))
$_SESSION["data"] = array();
foreach($_POST['checkboxes'] as $key => $value){
$_SESSION["data"] = "$value";
}
// Print out the final array, if there's a parameter final!
if (isset($_GET["final"]))
foreach ($_SESSION["data"] as $data)
echo $data;
?>
And for the JavaScript, you need to reset the thingy:
<form id="checkboxes">
<input type="checkbox" id="1" name="checkboxes[]" value="1" />
<input type="checkbox" id="2" name="checkboxes[]" value="2" />
<input type="checkbox" id="3" name="checkboxes[]" value="3" />
<input type="checkbox" id="1" name="checkboxes[]" value="4" />
<input type="checkbox" id="1" name="checkboxes[]" value="5" />
<input type="button" id="button" name="submit" value="Submit" />
</form>
<script type="text/javascript">
$(function() {
$("#button").click(function() {
$.ajax({
type: "POST",
url: "process.php",
data: $("form#checkboxes").serialize(),
success: function(data) {
$("#div").load('success.php');
$("form#checkboxes > input[type='checkbox']").removeAttr('checked');
}
});
});
});
</script>
You would use the success function of the ajax call. We would get the value of each checked box and then submit the form through ajax, prevent Default, and then uncheck all boxes after form submit.
$('something').submit(function(e){
e.preventDefault();
var checked = [];
$.each($('input[type=checkbox]'), function(i,v){
if($(this).is(':checked')){
checked.push($(this).val());
}
});
$.ajax({
url: 'someurl.ext',
type: 'post',
data: checked,
success: function(data){
$.each($('input[type=checkbox]'), function(i,v){
$(this).prop('checked', false');
});
}
});
});

Categories