I am getting the list of users, the last column in my table is for user's status, default is new
and admin can change the status new to done
, I am new in Codeigniter so not getting an idea what went wrong in my code.
My view:
<thead>
<th>Sr.no</th>
<th>Hospital Name</th>
<th>Blood type</th>
<th>Status</th>
</thead>
<tbody>
<?php if(count($all_blood>0))
{
$i=0;
foreach ($all_blood as $user)
{
$i++;
?>
<tr>
<td><?php echo $i ?></td>
<td><?php echo $user->h_name ?></td>
<td><?php echo $user->btype?></td>
<td>
<select id="statusChange[<?= $user->req_id ?>]" <?php if ($user->status == 1) :?> disabled <?php endif;?> class="check">
<option value="0" <?php if (0 == $user->status) : ?> selected<?php endif; ?>>New</option>
<option value="1" <?php if (1 == $user->status) : ?> selected<?php endif; ?>>Done</option>
</select>
</td>
<td>
<?php $id = $user->req_id;?>
<a href="<?php echo site_url("users/delete/$id")?>" class="delete">Delete</a>
</td>
</tr>
<script>
$(window).on('load', function() {
$("#statusChange[<?= $user->req_id ?>]").on('change',function()
{
console.log("change");
$.ajax({
type:'POST',
data:{id:"<?= $user->req_id?>"},
url:'<?php echo base_url("getData/change_status"); ?>',
success:function(data){
console.log(data);
}
});
event.preventDefault();
});
});
</script>
<?php }
}?>
</tbody>
now I try to put ajax out of foreach loop, but there is an issue that I am not getting req_id
for my ajax, which I need to send to controller, here is another issue, I am trying to use dynamic class
or id
so it will only which admin will select, but it is not working
if I change my dropdown's id to simple "statusChange" the function .on('change')
works very well, but if I use dynamic it is not invoking