I can't solve a problem and need help.
Let me briefly explain what to do.
As you can see above, I have the data I pulled from the database and these are the radio inputs.
Each one has unique database ids and I want to check here with jquery.
For example, if the phone does not select the memory partition, I want to give a warning. Since the data coming here comes with a loop, the same thing will enter the loop.
If it is selected, I want to get the values in it.
I would be glad if you could help me.
HTML
<form action="" type="POST" onsubmit="return false;">
<div id="form_step_1">
<div class="container">
<div class="row">
<?php
$features_title_query = $db->prepare("SELECT * FROM features_title WHERE features_title_product_id = ?");
$features_title_query->execute([Guvenlik($product_id)]);
$features_title_number = $features_title_query->rowCount();
$features_title_fetch = $features_title_query->fetchAll(PDO::FETCH_ASSOC);
foreach ($features_title_fetch as $features_title) {
?>
<div class="talepler mb-3">
<H4><?php echo $features_title["features_title_name"]; ?></H4>
<?php
$features_data_query = $db->prepare("SELECT * FROM features_data WHERE features_data_features_title_id = ?");
$features_data_query->execute([Guvenlik($features_title["id"])]);
$features_data_number = $features_data_query->rowCount();
$features_data_fetch = $features_data_query->fetchAll(PDO::FETCH_ASSOC);
if ($features_data_number > 0) {
foreach ($features_data_fetch as $features_data) {
?>
<div class="row mb-3" style="display: inline-block">
<div class="col-sm-3 col-md-4 col-lg-3 titles">
<input style="display: none" class="inputs" type="radio" id="<?php echo Guvenlik($features_data["id"]); ?>" name="<?php echo Guvenlik($features_data["features_data_features_title_id"]);?>">
<label class="btn btn-pill" style="display: inline-block" for="<?php echo Guvenlik($features_data["id"]); ?>"><?php echo Guvenlik($features_data["features_data_name"]); ?></label>
<style>
.inputs:checked + label {
background-color: #0034d0;
color: white;
}
.inputs + label {
border: 1px solid blue ;
}
</style>
</div>
</div>
<?php
}
}
?>
</div>
<?php } ?>
<button type="submit" class="btn btn-success" id="gonder">Gönder</button>
</div>
</div>
</div>
</form>
JS
$(document).ready(function () {
$('.inputs').on('click', function () {
var $id = $(this).val();
var $ids = "#" + $(this).val();
if ($($ids).attr('checked', true)) {
$($ids).attr('checked', false);
} else {
$($ids).attr('checked', true);
}
})
});
Aucun commentaire:
Enregistrer un commentaire