I have a project to learn something. I have a booking system that books movies seats. It is all well done, but now I want to put a custom value on a checkbox and when it is checked I want to get the value from that attribute and I want to pass it into an ajax request. Here is my code:
<script>
$(document).ready(function (e){
$("#frmRezerva").on('submit',(function(e){
e.preventDefault();
var $fields = $(this).find('input[name="scaun_film[]"]:checked');
if (!$fields.length) {
alert('Selectati un scaun sau mai multe!');
return false;
}
var arr=[];
$.each($("input[name='scaun_film[]']:checked"), function(){
arr.push($(this).val());
});
//console.log(arr)
$("#mail-status3").hide();
$('#rezBtn').hide();
$('#loader-icon3').show();
$.ajax({
url: "rezervare.php",
type: "POST",
dataType:'json',
data: {
"arr": arr,
"id_movie":$('input[name="id_movie"]').val(),
"nume_film":$('input[name="nume_film"]').val(),
"gen_film":$('input[name="nume_film"]').val(),
"nota_film":$('input[name="nota_film"]').val(),
"user_id":$('input[name="user_id"]').val(),
"user_email":$('input[name="user_email"]').val(),
"data_film":$('select[name="data_film"]').val(),
"bilete_film":$('input[name="bilete_film"]').val(),
"cinematograf":$('select[name="cinematograf"]').val()},
success: function(response){
window.setTimeout(function(){location.reload()},2000)
$("#mail-status3").show();
$('#loader-icon3').hide();
if(response.type == "error") {
$('#rezBtn').show();
$("#mail-status3").attr("class","alert alert-danger");
} else if(response.type == "message"){
$('#rezBtn').show();
$("#mail-status3").attr("class","alert alert-success");
}
$("#mail-status3").html(response.text);
},
error: function(){}
});
}));
});
</script>
Here is my jquery where i select if the checkbox was checked. I can get the value but I want the same thing but only from a custom attribute. My custom attribute is seatName with a value from the database. EDIT: html here is :
<?php
$sqlsq = "SELECT * FROM scaune WHERE id_scaun_movie='{$_GET['id_movie']}'";
$resultsq = mysqli_query($conn, $sqlsq);
while($rs = mysqli_fetch_assoc($resultsq)){?>
<?php if($rs['ocupat'] == 1){?>
<div class="box">
<label>
<input type="checkbox" value="<?=$rs['id'];?>" disabled checked><span class="label-text"></span>
</label>
</div>
<?php }else{?>
<div class="box">
<label>
<input type="checkbox" value="<?=$rs['id'];?>" seatName="<?=$rs['scaun'];?>" name="scaun_film[]"><span class="label-text"></span>
</label>
</div>
<?php } ?>
<?php } ?>
So what i need to do is to select chair name and id of that chair to update in mysql rezerved, but i dont find a solution to get id and name of chair when is checked also i need to be more than 1 so if is checked 3 chairs to get all name seats checked. Thanks!
Aucun commentaire:
Enregistrer un commentaire