I have table which contain following data structure,
#table
ID payroll_cat_name payroll_cat_code category_type amount
1 Provident Fund PF dedution 1000
2 Basic Pay BC earning 35000
3 Travelling TA earning 6500
4 Home Allowance HM earning 12000
5 Tax TX dedution 500
I am fetching this all data with this code below,
<?php
include "../db.php";
$select_payroll_category = "SELECT * from payroll_category";
$employee_payroll_result = mysqli_query($con,$select_payroll_category);
?>
<table>
<thead style="color: #222426;">
<tr>
<th>
<div class="form-check">
<input type="checkbox" class="form-check-input checkAll">
<label class="form-check-label">ID</label>
</div>
</th>
<th>Category name</th>
<th>Category code</th>
<th>Category Type</th>
<th>Category Amount</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($employee_payroll_result)) {
echo "<tr style='color:#222426;'>
<td>
<div class='form-check'>
<input type='checkbox' name='payroll_group' value=".$row["amount"]."class='form-check-input'>
<label class='form-check-label' style='color:#fff;'>".$row["payroll_cat_id"]."</label>
</div>
</td>
<td>".$row["payroll_cat_name"]."</td>
<td>".$row["payroll_cat_code"]."</td>
<td>".$row["category_type"]."</td>
<td>".$row["amount"]."</td>
</tr>";
}
?>
</tbody>
</table>
<button id="button">save</button>
<p id="result"></p>
Now On button
click I want to calculate the amount based on category_type,
If the category is earning
then it will add the amount ,
And if the category is dedution
then it will subtract the amount,
Using jquery, I want to perform this
Following is my jquery code which I have tried,
$(document).ready(function(){
$("#button").click(function(){
var favorite = [];
$.each($("input[name='payroll_group']:checked"), function(){
favorite.push($(this).val());
});
var total =
console.log("My favourite sports are: " + favorite);
$('#result').html(favorite);
});
})
</script>
By using this code I m getting 1000,35000,6500
the value of amount Which I have ticked in checkbox
Aucun commentaire:
Enregistrer un commentaire