mercredi 15 février 2017

dynamic checkbox- determine where checkbox falls according to id from php and pass too ajax

hello i have some PHP code that generates data and i also have some chexkboxes which i want the user to tick up. my current code works for detecting all checkboxes clicked on that page but what i want is to be able to determine which checkbox falls under which category according to dynamic values generated from database in php. please look at my code to get a clearer understanding

<?php 
$iio = "SELECT * FROM `products`";
$th = mysqli_query($con, $iio);
while($not = mysqli_fetch_array($th)){
$id = $not['id'];
$product_name = $not['product_name'];
$product_image = $not['product_image'];
$product_price = $not['product_price'];
$product_desc = $not['product_desc'];
$category = $not['category'];
$subcategory = $not['subcategory'];
$status = $not['status'];
?>
    <input type="text" class="cam" id="size_<?php echo $id ?>">



<div style="position:relative;margin-left:130px!important;">
<input type="checkbox" id="table_<?php echo $id ?>" name="subca[]"  value="Monday"> Monday
<input type="checkbox" id="table_<?php echo $id ?>" name="subca[]"  value="Tuesday"> Tuesday
<input type="checkbox" id="table_<?php echo $id ?>" name="subca[]"  value="Wednesday"> Wednesday
<br/>
<input type="checkbox" id="table_<?php echo $id ?>" name="subca[]"  value="Thursday"> Thursday
<input type="checkbox" id="table_<?php echo $id ?>" name="subca[]"  value="Friday"> Friday
<input type="checkbox" id="table_<?php echo $id ?>" name="subca[]"  value="Saturday"> Saturday
</div>

  <?php } ?>
     <script>
$(".maxi").on("click",function() {
var productid = $(this).attr('id');
var buckets = new Array();
$("input[name='subca[]']:checked" ).each( function() {  //works fine for detecting all checkboxes ticked on that page but since i have dynamic information from database i have to be able to know where each check box falls under according to unique id from php
buckets.push( $( this ).val() );
});
alert(buckets); //gives all checkbox value
if ((id == "")) {
$(this).css({'border-color': 'red', 'border-width': '1px', 'border-style': 'solid'}); // ('border', '2px solid red;');
} else { 
$.ajax({ 
type: "POST",
url: "ajaxaddpro.php", 
data: {id: id}, 
cache: false, 
success: function(html){
$('#butto_'+id).fadeOut(100);
}
});
e.preventDefault();
} 
});
</script>




Aucun commentaire:

Enregistrer un commentaire