0

I want to display pdf icon only when the field (WO_doc) is not empty. I don't know what I am doing wrong while writing the if statement. Please help.

<script type="text/javascript">
      $( "select[name='PEF_id']").change(function () {
       var Pefid = $(this).val();
        if(Pefid) {

        $.ajax({
            url: "<?php echo site_url('Admin/showwo');?>",
            dataType: 'Json',
            data: {'PEF_id': Pefid}, 
             success: function(response){
              $(".displayNone").removeClass("displayNone").addClass("displayHidden");
             $.each(response.wo,function(key, value) {
              $('.wodata').append('<tr>\
              <td>'+value['WO_no']+'</td>\
              <td>'+value['WO_date']+'</td>\
              <td>'+value['Agency_name']+'</td>\
              <td>'+value['WO_amount']+'</td>\
              <?php if("?>'+value['WO_doc']+'<?php" != null) { ?>\    ***this if condition is not working***
              <td><a href= "<?php echo site_url('/Admin/showwodoc/')?>'+value['WO_doc']+'" target="_blank" <i class="fa fa-file-pdf-o" style="font-size:36px"></i></a></td> <?php } else { ?> <td></td> <?php } ?>\
              <td><a href="<?php echo site_url('Admin/edit_wo/')?>'+value['WO_no']+'"><button type="submit" name="submit" class="btn btn-success">Update</button></a></td>\ 
              <td><button type="submit" name="submit" value="'+value['WO_no']+'" class="button-del btn btn-danger">Close this WO</button></td>\
              </tr>');
              });
             
        }
      });
    }
  });
</script> 
  • PHP is run on the server, JS is run on the client. While you can `echo` **PHP** variables inside JS you can't mix PHP and JS variables like that – brombeer Jul 21 '22 at 05:55
  • Go have a read of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – CBroe Jul 21 '22 at 07:04
  • This should be a _JavaScript_ if/else, resp. use the ternary opertor. – CBroe Jul 21 '22 at 07:06

0 Answers0