1

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

Sagar Parikh
  • 288
  • 5
  • 20
  • `$user->req_id` is not empty? There is a value? – user141080 Feb 24 '20 at 15:19
  • @user141080 yes, its value – Sagar Parikh Feb 25 '20 at 05:45
  • 1
    Your problem has nothing to do with Codeigintor, the brackets inside the id tag are the problem. If you want to use them you have to escape them. This link could be helpful [https://stackoverflow.com/questions/1239095/find-dom-element-by-id-when-id-contains-square-brackets](https://stackoverflow.com/questions/1239095/find-dom-element-by-id-when-id-contains-square-brackets) – user141080 Feb 25 '20 at 20:09

0 Answers0