i have this code in index.php :
<table class = "table table-bordered table-responsive ">
<thead>
<tr>
<th>Segment</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($data as $fetch): ?>
<tr>
<input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id']?>">
<td class="segment" contenteditable="true"><?= $fetch['segment'] ?></td>
<td class="text-center">
<button class = "btn btn-default action-btn" data-id="<?= $fetch['id'] ?>" data-action="update">
<span class = "glyphicon glyphicon-edit"></span> Update
</button>
|
<button class = "btn btn-success activate-btn action-btn" data-id="<?= $fetch['id'] ?>" id="<?= $fetch['id'] ?>" type="submit" data-action="activate">
<span class = "glyphicon glyphicon-check"></span> Activate
</button>
<button style="display:none" class = "btn btn-danger deactivate-btn action-btn " data-id="<?= $fetch['id'] ?>" id="<?= $fetch['id'] ?>" data-action="deactivate">
<span class = "glyphicon glyphicon-folder-close"></span> deactivate
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
all i want is:
if segment is activated to show deactivate button and if is already deactivated show activate button
this is the ajax call:
<script type="text/javascript">
$(".action-btn").on("click", function(e) {
var id = $(this).attr("data-id");
var segment = $(this).parents("tr").find("td.segment").html();
var action = $(this).attr("data-action");
$.ajax({
"url": "action.php",
"method": "post",
"data": {
"id": id,
"segment": segment,
"action": action
},
success: function(data) {
alert(data);
}
});
});
</script>
<script>
$(document).on("click",".activate-btn", function() {
var id = $(this).attr("data-id");
var segment = $(this).parents("tr").find("td.segment").html();
var action = $(this).attr("data-action");
$(this).hide(); $("#"+id).show(); $("#"+id,".deactivate-btn").show();
console.log();
});
$(document).on("click",".deactivate-btn", function() {
$(this).show();
$("#"+id).show();
$("#"+id,".activate-btn").show();
});
</script>
now all the page is showing the activate button even its activated already plus if it never change to deactivate after clicking please help thank u